class

CogUtil::RandGen

Inherits Reference < Object

High-quality random number generator based on Mersenne Twister Crystal's built-in Random class already uses a high-quality algorithm, so we wrap it with OpenCog-specific functionality

Constructors

new(seed : UInt32 | Nil = nil)
Source

Class methods

choose(array : Array(T)) : T forall T
Source
default

Get default instance

Source
randbool

Class methods using default generator

Source
randbytes(size : Int32) : Bytes
Source
randdouble(min : Float64, max : Float64) : Float64
Source
randdouble(max : Float64) : Float64
Source
randdouble
Source
randfloat(min : Float64, max : Float64) : Float64
Source
randfloat(max : Float64) : Float64
Source
randfloat
Source
randint(min : Int32, max : Int32) : Int32
Source
randint(max : Int32) : Int32
Source
randnormal(mean : Float64 = 0.0, stddev : Float64 = 1.0) : Float64
Source
sample(array : Array(T), count : Int32) : Array(T) forall T
Source
seed(seed : UInt32)

Seed the default generator

Source
shuffle(array : Array(T)) : Array(T) forall T
Source
shuffle!(array : Array(T)) : Array(T) forall T
Source

Instance methods

choose(array : Array(T)) : T forall T

Random choice from array

Source
randbool

Generate random boolean

Source
randbytes(size : Int32) : Bytes

Generate random bytes

Source
randdouble(min : Float64, max : Float64) : Float64
Source
randdouble(max : Float64) : Float64
Source
randdouble

Generate random double (alias for randfloat)

Source
randfloat(min : Float64, max : Float64) : Float64

Generate random float in range [min, max)

Source
randfloat(max : Float64) : Float64

Generate random float in range [0.0, max)

Source
randfloat

Generate random float in range [0.0, 1.0)

Source
randint(min : Int32, max : Int32) : Int32

Generate random integer in range [min, max)

Source
randint(max : Int32) : Int32

Generate random integer in range [0, max)

Source
randnormal(mean : Float64 = 0.0, stddev : Float64 = 1.0) : Float64

Generate random number from normal distribution Uses Box-Muller transform

Source
sample(array : Array(T), count : Int32) : Array(T) forall T

Random sample from array without replacement

Source
shuffle(array : Array(T)) : Array(T) forall T

Return shuffled copy of array

Source
shuffle!(array : Array(T)) : Array(T) forall T

Shuffle array in place

Source