Pseudo-random numbers/PCG32: Difference between revisions
→{{header|Wren}}: Oops, posted code for another task!
(Added Wren) |
(→{{header|Wren}}: Oops, posted code for another task!) |
||
Line 154:
<lang ecmascript>import "/big" for BigInt
var Const = BigInt.
var Mask64 = (BigInt.one << 64) - BigInt.one
var Mask32 = (BigInt.one << 32) - BigInt.one
class
construct new(
_state =
_inc = BigInt.fromBaseString("da3e39cb94b95bdb", 16)
}
seed(
_inc = ((seedSequence << BigInt.one) | BigInt.one) & Mask64
nextInt
_state = _state + seedState
nextInt
}
nextInt {
var
▲ _state = x
▲ return (((x * Const) & Mask64) >> 32) & Mask32
}
Line 177 ⟶ 183:
}
var randomGen =
randomGen.seed(BigInt.new(42), BigInt.new(54))
for (i in 0..4) System.print(randomGen.nextInt)
var counts = List.filled(5, 0)
randomGen.seed(BigInt.new(987654321), BigInt.one)
for (i in 1..1e5) {
var i = (randomGen.nextFloat * 5).floor
|