 USING: accessors alien.c-types alien.data arrays assocs
 byte-arrays byte-vectors combinators fry io.backend io.binary
 kernel locals math math.bitwise math.constants math.functions
-math.order math.ranges namespaces sequences sets summary system
-vocabs.loader ;
+math.order math.ranges namespaces sequences sequences.private
+sets summary system vocabs.loader ;
 IN: random
 
 SYMBOL: system-random-generator

        [ length random-integer ] keep nth
    ] if-empty ;

: random-32 ( -- n ) random-generator get random-32* ;

: randomize-n-last ( seq n -- seq ) 
    [ dup length dup ] dip - 1 max '[ dup _ > ] 
    [ [ random ] [ 1 - ] bi [ pick exchange ] keep ]
    while drop ;

: randomize ( seq -- randomized )


M: f random-32* ( obj -- * ) no-random-number-generator ;

: random-32 ( -- n ) random-generator get random-32* ;

: random-bytes ( n -- byte-array )
    random-generator get random-bytes* ;

<PRIVATE

: (random-integer) ( bits -- n required-bits )
    [ random-32 32 ] dip 32 - [ dup 0 > ] [
        [ 32 shift random-32 + ] [ 32 + ] [ 32 - ] tri*
    ] while drop ;

: random-integer ( n -- n' )
    dup next-power-of-2 log2 (random-integer)
    [ * ] [ 2^ /i ] bi* ;

PRIVATE>

