This repository has been archived by the owner on Aug 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
mp_isaac.inc
100 lines (79 loc) · 2.4 KB
/
mp_isaac.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
{---------------------------------------------------------------------------}
{------------ mp include file for ISAAC random number generator ------------}
{---------------------------------------------------------------------------}
uses isaac;
var
mp_ctx: isaac_ctx; {Global ISAAC context}
{---------------------------------------------------------------------------}
function mp_random_byte: byte;
{-Returns a random byte}
begin
mp_random_byte := isaac_word(mp_ctx) and $FF;
end;
{---------------------------------------------------------------------------}
function mp_random_long: longint;
{-Returns a random positive longint}
begin
mp_random_long := isaac_long(mp_ctx)
end;
{---------------------------------------------------------------------------}
function mp_random_int: longint;
{-Returns a random signed longint}
begin
isaac_next(mp_ctx);
mp_random_int := mp_ctx.nextres;
end;
{---------------------------------------------------------------------------}
function mp_random_digit: mp_digit;
{-Returns a random mp_digit}
begin
isaac_next(mp_ctx);
mp_random_digit := mp_digit(mp_ctx.nextres and MP_DIGIT_MAX);
end;
{---------------------------------------------------------------------------}
procedure mp_random_read(dest: pointer; len: word);
{-Read len bytes from the PRNG to dest}
begin
isaac_read(mp_ctx, dest, len);
end;
{---------------------------------------------------------------------------}
procedure mp_random_seed(const seed: array of longint);
{-Initialize PRNG with array of longint}
begin
isaac_inita(mp_ctx, seed, succ(High(seed)));
end;
{---------------------------------------------------------------------------}
procedure mp_random_randomize;
{-Initialize PRNG via randomize/TSC}
{$ifdef MPC_UseTSC}
var
seed: array[0..2] of longint;
{$endif}
begin
randomize;
{$ifdef MPC_UseTSC}
seed[0] := RandSeed;
{$ifdef BASM16}
asm
db $0f,$31
db $66; mov word ptr [seed+4], ax
db $66; mov word ptr [seed+8], dx
end;
{$else}
asm
dw $310F
mov dword ptr [seed+4], eax
mov dword ptr [seed+8], edx
end;
{$endif}
mp_random_seed(seed);
{$else}
isaac_init0(mp_ctx);
{$endif}
end;
{---------------------------------------------------------------------------}
function mp_random_word: word;
{-Returns a random word}
begin
mp_random_word := isaac_word(mp_ctx);
end;