Skip to content

Commit e6ab5bb

Browse files
committed
Merge pull request #10 from drhurdle/bug/calculation_error_in_xoroshiro128plus
Fixed calculation issue in xoroshiro128plus algorithm
2 parents 8b28f3c + 453ea12 commit e6ab5bb

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

HeavyCore/Common/Utilities/Random.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public struct PRNG {
2323
mutating func next() -> UInt {
2424
let s0: UInt = state[0]
2525
var s1 = state[1]
26-
let result = s0 &* s1
26+
let result = s0 &+ s1
2727

2828
s1 ^= s0
2929
state[0] = rotateLeft(s0, b: 55) ^ s1 ^ (s1 << 14)

Playgrounds/Core.playground/Pages/Random.xcplaygroundpage/Contents.swift

+17
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,21 @@ sameSeedCheck // Expected to be true
9595
"** EXPECT TO BE TRUE **"
9696
diffSeedCheck // Expected to be true
9797

98+
99+
x.nextUInt(0, max: 1)
100+
x.nextUInt(0, max: 1)
101+
x.nextUInt(0, max: 1)
102+
x.nextUInt(0, max: 1)
103+
x.nextUInt(0, max: 1)
104+
x.nextUInt(0, max: 1)
105+
x.nextUInt(0, max: 1)
106+
x.nextUInt(0, max: 1)
107+
x.nextUInt(0, max: 1)
108+
x.nextUInt(0, max: 1)
109+
x.nextUInt(0, max: 1)
110+
x.nextUInt(0, max: 1)
111+
x.nextUInt(0, max: 1)
112+
x.nextUInt(0, max: 1)
113+
x.nextUInt(0, max: 1)
114+
x.nextUInt(0, max: 1)
98115
//: [Next](@next)

0 commit comments

Comments
 (0)