std/num/random▲toc

Random numbers.

.

effect randomstd/num/random/random: HX

randomstd/num/random/random: HX effect.

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

Returns one of its arguments xstd/num/random/x: (sfc : sfc) -> int32 or ystd/num/random/y: (sfc : sfc) -> int32 based on a non-deterministic choice.

fun pseudo-random( seed : intstd/core/types/int: V, action : () -> <randomstd/num/random/random: HX|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: HX boolstd/core/types/bool: V

Return a random boolean.

fun random-double(): randomstd/num/random/random: HX doublestd/core/types/double: V

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

fun random-int(): randomstd/num/random/random: HX intstd/core/types/int: V

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

fun random-int32(): randomstd/num/random/random: HX int32std/core/types/int32: V

call random-int32std/num/random/random-int32: () -> random int32 operation of the randomstd/num/random/random: HX effect.

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

Return a strong random boolean.

fun srandom-double(): ndetstd/core/types/ndet: X doublestd/core/types/double: V

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

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

Generate a strong random double 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: HX,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 /dev/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/corestd/core, std/num/int32std/num/int32, std/num/doublestd/num/double