Generating random integers


The random vocabulary contains a protocol for generating random or pseudorandom numbers.

The “Mersenne Twister” pseudorandom number generator algorithm is the default generator stored in random-generator.

Generate a random object:
random ( obj -- elt )


Efficient 32-bit random numbers:
random-32 ( -- n )


Combinators to change the random number generator:
with-random ( obj quot -- )

with-system-random ( quot -- )

with-secure-random ( quot -- )


Implementation:
Random protocol

Randomizing a sequence:
randomize ( seq -- randomized )


Sampling a sequences:
sample ( seq n -- seq' )


Deleting a random element from a sequence:
delete-random ( seq -- elt )


Sequences of random numbers:
random-bytes ( n -- byte-array )

random-integers ( length n -- sequence )

random-units ( length -- sequence )


Random numbers with n bits:
random-bits ( numbits -- n )

random-bits* ( numbits -- n )