luz-random¶
Random number and data generation library included with Luz. No installation needed.
Core¶
random()¶
Random float between 0.0 and 1.0.
random_float(low, high)¶
Random float in the range [low, high).
random_int(low, high)¶
Random integer in the range [low, high] inclusive.
random_bool(chance)¶
Returns true with the given probability (0.0 – 1.0).
coin()¶
Returns true or false with equal probability.
random_sign()¶
Returns 1 or -1 at random.
random_normal(mean, std)¶
Gaussian-distributed random value.
seed(value)¶
Set the random seed for reproducible results.
Sequences¶
pick(list)¶
Pick one random element from a list.
sample(list, n)¶
Pick n unique elements from a list (no repetition).
shuffle(list)¶
Return a new shuffled copy of the list.
random_list(n, low, high)¶
Generate a list of n random integers.
weighted_pick(list, weights)¶
Pick a random element using a weight for each item.
Generators¶
random_color()¶
Returns a random hex color string.
random_token(length)¶
Alphanumeric random string.
random_pin(length)¶
Numeric PIN string.
random_uuid()¶
UUID v4-style identifier.
Dice¶
roll(sides)¶
Roll a die with sides faces.
roll_sum(n, sides)¶
Roll n dice and return the sum.
roll_all(n, sides)¶
Roll n dice and return all results as a list.
roll_advantage(sides) / roll_disadvantage(sides)¶
Roll twice and return the higher / lower result.
chance(probability)¶
Returns true with the given probability.
flip()¶
Returns "heads" or "tails".