~ chicken-core (master) /manual/Module (chicken random)
Trap1[[tags: manual]]2[[toc:]]34== Module (chicken random)56This module provides access to entropy (as provided by the operating7system) and a pseudo random number generator.89On UNIX systems entropy is by default obtained from {{/dev/urandom}}.10On Linux, the {{getrandom(2)}} system call is used instead, if available.11On OpenBSD it is {{arc4random_buf(3)}}, on Windows {{RtlGenRandom}}.1213The pseudo random number generator is an implementation of the14[[https://en.wikipedia.org/wiki/Well_equidistributed_long-period_linear|WELL]] algorithm.1516==== set-pseudo-random-seed!1718<procedure>(set-pseudo-random-seed! SEED [SIZE])</procedure>1920Set seed for the PRNG from the at most {{SIZE}} bytes of {{SEED}}.21which should be a bytevector containing random data.22If {{SIZE}} is not given, it defaults to the size of {{SEED}}. If {{SIZE}}23(or the size of {{SEED}}) is below the required size of the random24state used by the PRNG, then it will necessarily be initialized in a less25random manner as possible.262728==== pseudo-random-integer2930<procedure>(pseudo-random-integer RANGE)</procedure>3132Returns a uniformly distributed pseudo random integer between 0 and33{{RANGE-1}}, which may be a big integer.343536==== pseudo-random-real3738<procedure>(pseudo-random-real)</procedure>3940Returns a uniformly distributed pseudo-random inexact number between410 and 1.424344==== random-bytes4546<procedure>(random-bytes [BUF [SIZE]])</procedure>4748Returns random bytes from the available entropy source. If {{BUF}} is49given, it should be a string or byte vector which will be filled with up to50{{SIZE}} random bytes. {{SIZE}} defaults to the size of the {{BUF}}51argument. If no arguments are given, {{random-bytes}} returns a52freshly allocated byte vector of sufficient size to be used as a seed53for {{set-pseudo-random-seed!}}.545556---57Previous: [[Module (chicken process-context)]]5859Next: [[Module (chicken read-syntax)]]