 M:: cmwc random-32* ( cmwc -- n )
     cmwc dup mod>> '[ 1 + _ bitand ] change-i
     [ a>> ]
-    [ [ i>> ] [ Q>> ] bi nth * ]
+    [ [ i>> ] [ Q>> ] bi nth-unsafe * ]
     [ c>> + ] tri :> t!
 
     t -32 shift cmwc (>>c)

! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types arrays fry kernel locals math
math.bitwise random sequences specialized-arrays
specialized-arrays.instances.uint ;
IN: random.cmwc

! Multiply-with-carry RNG

        t cmwc b>> - 32 bits t!
    ] when

    cmwc [ r>> t - 32 bits dup ] [ i>> ] [ Q>> ] tri set-nth-unsafe ;

: cmwc-4096 ( -- cmwc )
    4096
