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.fromBaseStringnew("2545F4914F6CDD1D6364136223846793005", 16)
var Mask64 = (BigInt.one << 64) - BigInt.one
var Mask32 = (BigInt.one << 32) - BigInt.one
 
class XorshiftStarPcg32 {
construct new(state) {
_state = stateBigInt.fromBaseString("853c49e6748fea9b", & Mask6416)
_inc = BigInt.fromBaseString("da3e39cb94b95bdb", 16)
}
 
seed(numseedState, seedSequence) { _state = num & Mask64}
_state = xBigInt.zero
_inc = ((seedSequence << BigInt.one) | BigInt.one) & Mask64
nextInt
_state = _state + seedState
nextInt
}
 
nextInt {
var xold = _state
x_state = (xold*Const ^+ (x >> 12)_inc) & Mask64
xvar xorshifted = (x((old ^>> (x18) <<^ 25old) >> 27) & Mask64Mask32
xvar rot = (x ^ (xold >> 27)59) & Mask64Mask32
return (((xxorshifted *>> Constrot) &| Mask64(xorshifted << ((-rot) >>& 3231))) & Mask32
_state = x
return (((x * Const) & Mask64) >> 32) & Mask32
}
 
Line 177 ⟶ 183:
}
 
var randomGen = XorshiftStarPcg32.new(BigInt.new(1234567))
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
9,485

edits