std/num/random▲toc

Random numbers.

.

type randomstd/num/random/random: (E, V) -> V<e,a>

Operations:

fun random-int32
fun random-int32std/num/random/random-int32: () -> random int32
.

type sfcstd/num/random/sfc: V

Pseudo random number using sfc32 by Chris Doty-Humphrey. It is a “chaotic” pseudo random generator that uses 32-bit operations only (so we can be deterministic across architectures in results and performance). It has good statistical properties and passes PractRand and Big-crush. It uses a 32-bit counter to guarantee a worst-case cycle of 232. It has a 96-bit state, so the average period is 2127. The chance of a cycle of less than 2(32+max(96-k,0)) is 2-(32+k), (e.g. the chance of a cycle of less than 248 is 2-80). https://​pracrand.​sourceforge.​net/​RNG_​engines.​txt.

struct sfc-resultstd/num/random/sfc-result: V(rnd : int32std/core/types/int32: Vrstate : sfcstd/num/random/sfc: V)

Automatically generated. Retrieves the rnd constructor field of the sfc-resultstd/num/random/sfc-result: V type.

Automatically generated. Retrieves the rstate constructor field of the sfc-resultstd/num/random/sfc-result: V type.

fun choose( x : a, y : a ) : ndetstd/core/types/ndet: X a

Returns one of its arguments x or y based on a non-deterministic choice.

fun pseudo-random( seed : intstd/core/types/int: V, action : () -> <randomstd/num/random/random: (E, V) -> V|e> a ) : e a

Use pseudo random numbers given some initial seed. At most 64-bits of the initial seed are used. Do not use this for cryptographic applications (use strong-randomstd/num/random/strong-random: forall<a,e> (action : () -> <random,ndet|e> a) -> <ndet|e> a instead). Uses sfc32 by Chris Doty-Humphrey which is a fast random number generator with a 128-bit internal state which passes PractRand and BigCrush. The worst case minimum cycle is 2^32, where a potential cycle of 248^ has a chance of 2^-80^.

fun random-bool(): randomstd/num/random/random: (E, V) -> V boolstd/core/types/bool: V

Return a random boolean.

fun random-float64(): randomstd/num/random/random: (E, V) -> V float64std/core/types/float64: V

Return a random float64 in the range [0,1) using 52-bits of randomness.

fun random-int(): randomstd/num/random/random: (E, V) -> V intstd/core/types/int: V

Return a random integer in the range [-2^31, 231^).

fun random-int32(): randomstd/num/random/random: (E, V) -> V int32std/core/types/int32: V

Call the fun random-int32std/num/random/random-int32: () -> random int32 operation of the effect randomstd/num/random/random: (E, V) -> V.

fun random-int64(): randomstd/num/random/random: (E, V) -> V int64std/core/types/int64: V
fun srandom-bool(): ndetstd/core/types/ndet: X boolstd/core/types/bool: V

Return a strong random boolean.

fun srandom-float64(): ndetstd/core/types/ndet: X float64std/core/types/float64: V

Return a strong random float64std/core/types/float64: V in the range [0,1) using 52-bits of randomness.

fun srandom-float64-range( lo : float64std/core/types/float64: V, hi : float64std/core/types/float64: V ) : ndetstd/core/types/ndet: X float64std/core/types/float64: V

Generate a strong random float64 uniformly distributed in the range [lo, hi).

fun srandom-int(): ndetstd/core/types/ndet: X intstd/core/types/int: V

Return a strong random integer in the range [-2^31, 231^).

fun srandom-int32(): ndetstd/core/types/ndet: X int32std/core/types/int32: V

Return a strong random int32std/core/types/int32: V.

fun srandom-int32-range( lo : int32std/core/types/int32: V, hi : int32std/core/types/int32: V ) : ndetstd/core/types/ndet: X int32std/core/types/int32: V

Return a strong random int32std/core/types/int32: V uniformly distributed in the range [lo,hi).

fun srandom-is-strong(): ndetstd/core/types/ndet: X boolstd/core/types/bool: V

Are the strong random numbers generated from a strong random source? (like /dev/urandom).

fun strong-random( action : () -> <randomstd/num/random/random: (E, V) -> V,ndetstd/core/types/ndet: X|e> a ) : <ndetstd/core/types/ndet: X|e> a

Pick random numbers from a the best strong random source in the OS. (e.g. like /urandom, arc4random etc.). Use srandom-is-strongstd/num/random/srandom-is-strong: () -> ndet bool to test if the numbers are indeed based on a strong random source.

private import std/core/typesstd/core/types, std/core/hndstd/core/hnd, std/core/exnstd/core/exn, std/core/boolstd/core/bool, std/core/orderstd/core/order, std/core/charstd/core/char, std/core/intstd/core/int, std/core/vectorstd/core/vector, std/core/stringstd/core/string, std/core/sslicestd/core/sslice, std/core/liststd/core/list, std/core/maybestd/core/maybe, std/core/eitherstd/core/either, std/core/tuplestd/core/tuple, std/core/showstd/core/show, std/core/debugstd/core/debug, std/core/delayedstd/core/delayed, std/core/consolestd/core/console, std/corestd/core, std/num/int32std/num/int32, std/num/int64std/num/int64, std/num/float64std/num/float64