! See http://factorcode.org/license.txt for BSD license.
! mersenne twister based on
! http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/CODES/mt19937ar.c
-USING: alien.c-types kernel math namespaces sequences
+USING: alien.c-types alien.data kernel math namespaces sequences
sequences.private system init accessors math.ranges random
math.bitwise combinators specialized-arrays fry ;
SPECIALIZED-ARRAY: uint
CONSTANT: n 624
CONSTANT: m 397
-CONSTANT: a uint-array{ 0 HEX: 9908b0df }
+CONSTANT: a uint-array{ 0 0x9908b0df }
: y ( n seq -- y )
[ nth-unsafe 31 mask-bit ]
] each-integer ; inline
: init-mt-seq ( seed -- seq )
- 32 bits n <uint-array>
+ 32 bits n uint <c-array>
[ set-first ] [ init-mt-rest ] [ ] tri ; inline
: mt-temper ( y -- yt )
dup -11 shift bitxor
- dup 7 shift HEX: 9d2c5680 bitand bitxor
- dup 15 shift HEX: efc60000 bitand bitxor
+ dup 7 shift 0x9d2c5680 bitand bitxor
+ dup 15 shift 0xefc60000 bitand bitxor
dup -18 shift bitxor ; inline
: next-index ( mt -- i )