Data update

This commit is contained in:
Ingy döt Net 2024-07-13 15:19:22 -07:00
parent 29a5eea0d4
commit 5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions

View file

@ -0,0 +1,44 @@
#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

View file

@ -0,0 +1,34 @@
struct SplitMix64: RandomNumberGenerator {
var state: UInt64
init(seed: UInt64) {
state = seed
}
mutating func next() -> UInt64 {
state &+= 0x9e3779b97f4a7c15
var z = state
z = (z ^ (z >> 30)) &* 0xbf58476d1ce4e5b9
z = (z ^ (z >> 27)) &* 0x94d049bb133111eb
return z ^ (z >> 31)
}
mutating func nextFloat() -> Float64 {
Float64(next() >> 11) * 0x1.0p-53
}
}
do {
var split = SplitMix64(seed: 1234567)
print(split)
for _ in 0..<5 {
print(split.next())
}
split = .init(seed: 987654321)
print("\n\(split)")
var counts = [0, 0, 0, 0, 0]
for _ in 0..<100_000 {
let i = Int(split.nextFloat() * 5.0)
counts[i] += 1
}
for (i, count) in zip(0..., counts) {
print("\(i): \(count)")
}
}