random module

Seedable, non-cryptographic RNG. Don't use this for tokens or password resets — use crypto for those. Good for shuffling, sampling, and tests with reproducible randomness.

import "random" as random;

random.seed(42);                       // reproducible

print(random.float());                 // 0.0 ≤ x < 1.0
print(random.int(1, 6));               // dice roll, 1..6 inclusive
print(random.choice(["a","b","c"]));   // pick one
print(random.shuffle([1,2,3,4,5]));    // shuffled copy

API

FunctionDescription
random.seed(n)Seed the RNG. Same seed → same sequence.
random.next() → numberUniform [0.0, 1.0). (Same as random.float().)
random.float() → numberAlias for random.next().
random.bool() → boolTrue / false with equal probability.
random.probability(p) → boolTrue with probability p (0.0–1.0).
random.int(min, max) → numberInteger in [min, max] (inclusive both sides).
random.range(lo, hi) → numberUniform float in [lo, hi).
random.bytes(n) → stringn random bytes (still not cryptographic).
random.choice(xs) → elementPick one element uniformly at random.
random.shuffle(xs) → listFisher-Yates shuffle (new list).
random.sample(xs, k) → listk distinct elements without replacement.