1 ! Copyright (C) 2018 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien.c-types classes.struct kernel math
4 math.bitwise random sequences slots.syntax ;
7 ! http://xoshiro.di.unimi.it/xoshiro256starstar.c
16 CONSTANT: LONG-JUMP-256 {
23 STRUCT: xoshiro-256-star-star { s0 ulonglong } { s1 ulonglong } { s2 ulonglong } { s3 ulonglong } ;
25 : <xoshiro-256-star-star> ( s0 s1 s2 s3 -- obj )
26 xoshiro-256-star-star new
32 : rotl-256 ( x: uint64_t k: int -- out: uint64_t )
34 [ 64 swap - neg shift ] 2bi bitor 64 bits ; inline
36 :: (next-256) ( s0! s1! s2! s3! -- s0 s1 s2 s3 64-random-bits )
37 s1 5 * 7 rotl-256 9 * 64 bits :> 64-random-bits
38 s1 17 shift 64 bits :> t
45 s0 s1 s2 s3 64-random-bits ; inline
47 : next-256 ( xoshiro-256-star-star -- r64 )
48 dup get[ s0 s1 s2 s3 ] (next-256)
49 [ set[ s0 s1 s2 s3 ] drop ] dip ;
51 :: jump ( s0! s1! s2! s3! jump-table -- s0' s1' s2' s3' )
52 0 0 0 0 :> ( t0! t1! t2! t3! )
55 [ jump-table nth ] [ 1 swap shift ] bi* bitand 0 > [
61 s0 s1 s2 s3 (next-256) drop s3! s2! s1! s0!
66 : jump-256 ( s0 s1 s2 s3 -- s0' s1' s2' s3' ) JUMP-256 jump ;
67 : long-jump-256 ( s0 s1 s2 s3 -- s0' s1' s2' s3' ) LONG-JUMP-256 jump ;
69 M: xoshiro-256-star-star random-32*