3.15. kink/RAND¶
Provides pseudo random number generators using xorshift128+ algorithm, which is not cryptographically secure.
For details of xorshift128+, see the following paper:
http://vigna.di.unimi.it/ftp/papers/xorshiftplus.pdf
To get a PRNG, call RAND.new with a seed number. RAND.new returns a PRNG fun.
The PRNG fun takes a positive int num as the exclusive Upper_bound, then returns a random int num in the range of [0, Upper_bound).
Example:
:RAND.require_from('kink/')
:new_coin <- {(:Seed)
:rand = RAND.new(Seed)
{()
rand(2) % 2 == 0
}
}
:flip_coin <- new_coin(42)
stdout.print_line(flip_coin.repr) # => true
stdout.print_line(flip_coin.repr) # => true
stdout.print_line(flip_coin.repr) # => false
The Seed is internally transformed to 127 bits, then used as the initial state of the PRNG.
3.15.1. RAND.new(Seed)¶
Makes a PRNG fun.
Seed must be an int num. The Seed is internally transformed to 127 bits, then used as the initial state of the PRNG.
RAND.new returns a new PRNG fun. It takes a positive int num as the exclusive Upper_bound, then returns a random int num in the range of [0, Upper_bound).