nustack
ReferenceNu STD

random

Nu surface for Python's `random` module.

Module nustd.random.

Nu surface for Python's random module.

random is a function module - module-level functions over a global RNG, no central class - so the Nu surface mirrors that: free functions (random, randint, choice, sample, ...). Two layers behind it: functions (the typed wrappers) and interactions (the atoms each wrapper builds). Import it the way you would the stdlib:

from nustd.random import randint, choice
import nustd.random as random     # then random.randint(1, 6)

Every function reads the global RNG. The effectful / stateful pieces (seed, shuffle, getstate / setstate) are deferred until the effect model lands.

Call

NameCallMeaning
choicerandom.choice(seq)A random element of seq: mirrors random.choice(). Non-deterministic.
choicesrandom.choices(population, k)A k-sized list drawn with replacement: mirrors random.choices(). Non-deterministic.
expovariaterandom.expovariate(lambd)An exponential draw with rate lambd: mirrors random.expovariate(). Non-deterministic.
gaussrandom.gauss(mu, sigma)A Gaussian draw with mean mu and stdev sigma: mirrors random.gauss(). Non-deterministic.
getrandbitsrandom.getrandbits(k)A non-negative int with k random bits: mirrors random.getrandbits(). Non-deterministic.
normalvariaterandom.normalvariate(mu, sigma)A normal draw with mean mu and stdev sigma: mirrors random.normalvariate(). Non-deterministic.
randintrandom.randint(a, b)A random int N with a <= N <= b: mirrors random.randint(). Non-deterministic.
randomrandom.random()A random float in [0.0, 1.0): mirrors random.random(). Non-deterministic.
randrangerandom.randrange(start, stop)A random int in range(start, stop): mirrors random.randrange(). Non-deterministic.
samplerandom.sample(population, k)A k-sized list drawn without replacement: mirrors random.sample(). Non-deterministic.
triangularrandom.triangular(low, high)A triangular draw between low and high: mirrors random.triangular(). Non-deterministic.
uniformrandom.uniform(a, b)A random float in [a, b]: mirrors random.uniform(). Non-deterministic.

choice

A random element of seq: mirrors random.choice(). Non-deterministic.

random.choice(seq)

Path nustd.random.choice. Defined on nustd.random.functions, bound as a function. Builds Any.

Arguments

NameTypeDefaultMeaning
seqListArg[object]

Undocumented: example.

choices

A k-sized list drawn with replacement: mirrors random.choices(). Non-deterministic.

random.choices(population, k)

Path nustd.random.choices. Defined on nustd.random.functions, bound as a function. Builds List.

Arguments

NameTypeDefaultMeaning
populationListArg[object]
kIntArg

Undocumented: example.

expovariate

An exponential draw with rate lambd: mirrors random.expovariate(). Non-deterministic.

random.expovariate(lambd)

Path nustd.random.expovariate. Defined on nustd.random.functions, bound as a function. Builds Float.

Arguments

NameTypeDefaultMeaning
lambdFloatArg

Undocumented: example.

gauss

A Gaussian draw with mean mu and stdev sigma: mirrors random.gauss(). Non-deterministic.

random.gauss(mu, sigma)

Path nustd.random.gauss. Defined on nustd.random.functions, bound as a function. Builds Float.

Arguments

NameTypeDefaultMeaning
muFloatArg
sigmaFloatArg

Undocumented: example.

getrandbits

A non-negative int with k random bits: mirrors random.getrandbits(). Non-deterministic.

random.getrandbits(k)

Path nustd.random.getrandbits. Defined on nustd.random.functions, bound as a function. Builds Int.

Arguments

NameTypeDefaultMeaning
kIntArg

Undocumented: example.

normalvariate

A normal draw with mean mu and stdev sigma: mirrors random.normalvariate(). Non-deterministic.

random.normalvariate(mu, sigma)

Path nustd.random.normalvariate. Defined on nustd.random.functions, bound as a function. Builds Float.

Arguments

NameTypeDefaultMeaning
muFloatArg
sigmaFloatArg

Undocumented: example.

randint

A random int N with a <= N <= b: mirrors random.randint(). Non-deterministic.

random.randint(a, b)

Path nustd.random.randint. Defined on nustd.random.functions, bound as a function. Builds Int.

Arguments

NameTypeDefaultMeaning
aIntArg
bIntArg

Undocumented: example.

random

A random float in [0.0, 1.0): mirrors random.random(). Non-deterministic.

random.random()

Path nustd.random.random. Defined on nustd.random.functions, bound as a function. Builds Float.

Undocumented: example.

randrange

A random int in range(start, stop): mirrors random.randrange(). Non-deterministic.

random.randrange(start, stop)

Path nustd.random.randrange. Defined on nustd.random.functions, bound as a function. Builds Int.

Arguments

NameTypeDefaultMeaning
startIntArg
stopIntArg

Undocumented: example.

sample

A k-sized list drawn without replacement: mirrors random.sample(). Non-deterministic.

random.sample(population, k)

Path nustd.random.sample. Defined on nustd.random.functions, bound as a function. Builds List.

Arguments

NameTypeDefaultMeaning
populationListArg[object]
kIntArg

Undocumented: example.

triangular

A triangular draw between low and high: mirrors random.triangular(). Non-deterministic.

random.triangular(low, high)

Path nustd.random.triangular. Defined on nustd.random.functions, bound as a function. Builds Float.

Arguments

NameTypeDefaultMeaning
lowFloatArg
highFloatArg

Undocumented: example.

uniform

A random float in [a, b]: mirrors random.uniform(). Non-deterministic.

random.uniform(a, b)

Path nustd.random.uniform. Defined on nustd.random.functions, bound as a function. Builds Float.

Arguments

NameTypeDefaultMeaning
aFloatArg
bFloatArg

Undocumented: example.

On this page