Random number generation and probabilistic operations.
Random number generation and probabilistic operations.
(choose rng weights coll)
Probabilistically select one element from coll
. The weights
map
should be a map of coll
elements numerical weights. If an element does
not have an associated weight, it will be assigned a default of 0.5.
Note that a weight of 0 denotes that the element can never be chosen.
Probabilistically select one element from `coll`. The `weights` map should be a map of `coll` elements numerical weights. If an element does not have an associated weight, it will be assigned a default of 0.5. Note that a weight of 0 denotes that the element can never be chosen.
(choose-map rng weights m)
Probabilistically select one value from the map m
. The weights
map
should be a map from the keys of m
to numerical weights. If an
element does not have a weight, it will be assigned a default of 0.5.
Note that a weight of 0 denotes that the element can never be chosen.
Probabilistically select one value from the map `m`. The `weights` map should be a map from the keys of `m` to numerical weights. If an element does not have a weight, it will be assigned a default of 0.5. Note that a weight of 0 denotes that the element can never be chosen.
(rand rng)
(rand rng n)
Generate a pseudorandom, uniformly distributed double value between 0 and
n
(both inclusive).
See also: clojure.core/rand
Generate a pseudorandom, uniformly distributed double value between 0 and `n` (both inclusive). See also: `clojure.core/rand`
(rand-boolean rng prob)
Generate a pseudorandom boolean value where true
is returned with
probability prob
and false
with probablility 1 - prob
. This
function can be used to realize prob
, and is equivalent to generating
a Bernoulli-distributed value.
Generate a pseudorandom boolean value where `true` is returned with probability `prob` and `false` with probablility `1 - prob`. This function can be used to realize `prob`, and is equivalent to generating a Bernoulli-distributed value.
(rand-exp rng lambda)
Generate a pseudorandom, exponentially distributed double value with
mean (/ 1 lambda)
, where lambda
is the so-called "rate parameter".
Generate a pseudorandom, exponentially distributed double value with mean `(/ 1 lambda)`, where `lambda` is the so-called "rate parameter".
(rand-gaussian rng mean sd)
Generate a pseudorandom, normally distributed double value with mean
mean
and standard deviation sd
.
Generate a pseudorandom, normally distributed double value with mean `mean` and standard deviation `sd`.
(rand-int rng n)
Generate a pseudorandom, uniformly distributed integer value between 0
(inclusive) and n
(exclusive).
See also: clojure.core/rand-int
Generate a pseudorandom, uniformly distributed integer value between 0 (inclusive) and `n` (exclusive). See also: `clojure.core/rand-int`
(rand-nth rng coll)
Randomly select an element from coll
. Each element has an equal
probability of being selected.
Will throw an ::empty-coll
exception on an empty coll
.
See also: clojure.core/rand-nth
Randomly select an element from `coll`. Each element has an equal probability of being selected. Will throw an `::empty-coll` exception on an empty `coll`. See also: `clojure.core/rand-nth`
(rand-unbound-int rng)
Generate a pseudorandom, uniformly distributed integer value in the entire range of possible Java long/Clojure integer values.
Generate a pseudorandom, uniformly distributed integer value in the entire range of possible Java long/Clojure integer values.
(rand-uuid rng)
Generate a pseudorandom UUID (as a string).
Generate a pseudorandom UUID (as a string).
(random-sample rng prob)
(random-sample rng prob coll)
(random-sample rng prob coll weights)
Probabilistically sample elements from coll
, where each element has
prob
probability of being selected. If weights
are provided, then
the element associated with a weight has (+ prob weight)
probability
(up to 1.0) of being selected. Returns a transducer when coll
is not
provided.
See also: clojure.core/random-sample
Probabilistically sample elements from `coll`, where each element has `prob` probability of being selected. If `weights` are provided, then the element associated with a weight has `(+ prob weight)` probability (up to 1.0) of being selected. Returns a transducer when `coll` is not provided. See also: `clojure.core/random-sample`
(rng)
Create a pseudorandom RNG using an arbitrary seed value.
Create a pseudorandom RNG using an arbitrary seed value.
(seed-rng seed)
Create a seeded deterministic, pseudorandom RNG, in which two RNGs created
using the same value of seed
will output the same results.
Create a seeded deterministic, pseudorandom RNG, in which two RNGs created using the same value of `seed` will output the same results.
(shuffle rng coll)
(shuffle rng coll cnt)
Randomly shuffle coll
and return a lazy sequence as the result.
See also: clojure.core/shuffle
Randomly shuffle `coll` and return a lazy sequence as the result. See also: `clojure.core/shuffle`
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close