Plan 9 from Bell Labs’s /usr/web/sources/contrib/fgb/root/sys/src/cmd/4th/examples/gm.4th

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


\ George Marsaglia KISS random number generator
\ Copyright 2005, Bill Cook

Variable x
Variable y
Variable z
Variable w

: setx x ! ;
: sety y ! ;
: setz z ! ;
: setw w ! ;

: seed setw setz sety setx ;

: seex x @ . ;
: seey y @ . ;
: seez z @ . ;
: seew w @ . ;

: view seex seey seez seew ;

: ishft ( k,n ** ishft )
dup 0<> if dup 0> if lshift else negate rshift then then ;

: m ( k n ** m )
over swap ishft xor ;

: rx x @ 69069 * 1327217885 + dup x ! ;

: ry y @ 13 m -17 m 5 m dup y ! ;

: rz z @ dup 65535 and 18000 * swap -16 ishft + dup z ! ;

: rw w @ dup 65535 and 30903 * swap -16 ishft + dup w ! ;

: kiss rz 16 ishft rw + rx + ry + ;

: preset 123456789 362436069 521288629 916191069 seed ;

: kisses 0 ?do kiss + loop ;
: test kiss 8 kisses . ;

: .x1 dup 255 24 lshift and 24 rshift hex . decimal ;
: .x2 dup 255 16 lshift and 16 rshift hex . decimal ;
: .x3 dup 255 08 lshift and 08 rshift hex . decimal ;
: .x4 dup 255           and           hex . decimal ;
: .xs .x1 .x2 .x3 .x4 ;
preset view kiss . view

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].