std.math.random

+default+

rand

added in 3.0

(rand)(rand rng)

returns a random double between 0 and 1

(rand) ;;0.19755427425784822 => number?

(rand (rand-gen)) ;;0.8479218396605446 => number?

rand-digits

added in 3.0

(rand-digits n)

constructs a n digit string

(rand-digits 10) ;; “9417985847” => string?

rand-gen

added in 3.0

(rand-gen)(rand-gen seed)(rand-gen seed type)

creates a random number generator

(rand-gen) => org.apache.commons.math3.random.MersenneTwister

rand-int

added in 3.0

(rand-int n)(rand-int n rng)

returns a random integer less than n

(rand-int 100) ;; 16 => integer?

rand-normal

added in 3.0

(rand-normal)(rand-normal rng)

returns a random number corresponding to the normal distribution

(rand-normal) ;;-0.6591021470679017 => number?

rand-nth

added in 3.0

(rand-nth coll)(rand-nth coll rng)

returns a random element in an array

(rand-nth :a :b :c) => #{:a :b :c}

rand-sample

added in 3.0

(rand-sample coll proportions)

takes from the collection given specified proportions

(rand-sample :a :b :c 1 2 3) => keyword?

rand-seed!

added in 3.0

(rand-seed! seed)(rand-seed! rng seed)

sets the seed of a given random number generator

(-> (rand-gen) (rand-seed! 10) (rand)) => (any 0.77132064549269 0.5711645232847797)