This repository was archived by the owner on Aug 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmp_taus.inc
More file actions
104 lines (84 loc) · 2.53 KB
/
mp_taus.inc
File metadata and controls
104 lines (84 loc) · 2.53 KB
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
101
102
103
104
{---------------------------------------------------------------------------}
{------------ mp include file for taus88 random number generator -----------}
{---------------------------------------------------------------------------}
uses taus88;
var
mp_ctx: taus88_ctx; {Global taus88 context}
{---------------------------------------------------------------------------}
function mp_random_byte: byte;
{-Returns a random byte}
begin
mp_random_byte := taus88_word(mp_ctx) and $FF;
end;
{---------------------------------------------------------------------------}
function mp_random_long: longint;
{-Returns a random positive longint}
begin
mp_random_long := taus88_long(mp_ctx)
end;
{---------------------------------------------------------------------------}
function mp_random_int: longint;
{-Returns a random signed longint}
begin
taus88_next(mp_ctx);
mp_random_int := mp_ctx.nr;
end;
{---------------------------------------------------------------------------}
function mp_random_digit: mp_digit;
{-Returns a random mp_digit}
begin
taus88_next(mp_ctx);
mp_random_digit := mp_digit(mp_ctx.nr and MP_DIGIT_MAX);
end;
{---------------------------------------------------------------------------}
procedure mp_random_read(dest: pointer; len: word);
{-Read len bytes from the PRNG to dest}
begin
taus88_read(mp_ctx, dest, len);
end;
{---------------------------------------------------------------------------}
procedure mp_random_seed(const seed: array of longint);
{-Initialize PRNG with array of longint}
var
s1,s2,s3: longint;
begin
s1 := seed[0];
if high(seed)>0 then s2 := seed[1] else s2 := 0;
if high(seed)>1 then s3 := seed[2] else s3 := 0;
taus88_init3(mp_ctx,s1,s2,s3);
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}
taus88_init0(mp_ctx);
{$endif}
end;
{---------------------------------------------------------------------------}
function mp_random_word: word;
{-Returns a random word}
begin
mp_random_word := taus88_word(mp_ctx);
end;