44 lines
944 B
Text
44 lines
944 B
Text
#define floor(x) ((x*2.0-0.5) Shr 1)
|
|
|
|
Const As Ulongint mask64 = &HFFFFFFFFFFFFFFFF
|
|
Const As Ulongint C1 = &H9E3779B97F4A7C15
|
|
Const As Ulongint C2 = &HBF58476D1CE4E5B9
|
|
Const As Ulongint C3 = &H94D049BB133111EB
|
|
|
|
Dim Shared As Ulongint state
|
|
|
|
Sub seed(num As Ulongint)
|
|
state = num And mask64
|
|
End Sub
|
|
|
|
Function next_int() As Ulongint
|
|
' return random int between 0 and 2^64
|
|
Dim As Ulongint z = state
|
|
state += C1
|
|
z = (z Xor (z Shr 30)) * C2
|
|
z = (z Xor (z Shr 27)) * C3
|
|
Return z Xor (z Shr 31)
|
|
End Function
|
|
|
|
Function next_float() As Double
|
|
' return random float between 0 and 1
|
|
Return next_int() / (2 ^ 64)
|
|
End Function
|
|
|
|
Dim As Integer i, hist(4)
|
|
|
|
seed(1234567)
|
|
For i = 0 To 4
|
|
Print next_int()
|
|
Next i
|
|
|
|
Print !"\nThe counts for 100,000 repetitions are:"
|
|
seed(987654321)
|
|
For i = 1 To 100000
|
|
hist(floor(next_float() * 5)) += 1
|
|
Next i
|
|
For i = 0 To 4
|
|
Print Using "hist(#) = #####"; i; hist(i)
|
|
Next i
|
|
|
|
Sleep
|