Standard Library: Generators

dig


[%dig: count?]

string

Prints a uniformly random decimal digit. If count is specified, repeats count times.

Parameters

countint (optional)
The number of digits to generate. Defaults to 1.

Example

# Generate a random 32-character decimal string
[dig:32] # ~> 01952208554533821061510695429126

digh


[%digh: count?]

string

Prints a uniformly random lowercase hexadecimal digit. If count is specified, repeats count times.

Parameters

countint (optional)
The number of digits to generate. Defaults to 1.

Example

# Generate a random 32-character hex string
[digh:32] # ~> f4e5bef31ea02eac22f220e68e837587

dignz


[%dignz: count?]

string

Prints a uniformly random non-zero decimal digit. If count is specified, repeats count times.

Parameters

countint (optional)
The number of digits to generate. Defaults to 1.

Example

# Generate a random 32-character decimal string without zeros
[dignz:32] # ~> 92558761934966287236132511739511

maybe


[%maybe: p?]

bool

Returns a bool value with p probability of being true.

p must be either a float or empty. If omitted, it will default to 0.5.

Parameters

pfloat | empty
The probability (0.0 <= p <= 1.0) of the printed boolean being true. If omitted or empty, defaults to 0.5.

rand


[%rand: a; b]

int

Prints a random integer with uniform distribution between a and b (both inclusive).

Parameters

aint
The first inclusive bound of the random number.

bint
The second inclusive bound of the random number.

Example

# Choose a number by fair dice roll.
You roll a '[rand:1;6].

# ~> You roll a 4.

randf


[%randf: a; b]

float

Prints a random float with uniform distribution between a (inclusive) and b (exclusive).

Parameters

afloat
The first inclusive bound of the random number.

bfloat
The second inclusive bound of the random number.

rand-list


[%rand-list: a; b; n]

list

Prints a list of n random integers with uniform distribution between a and b (both inclusive).

Parameters

aint
The first inclusive bound of the random numbers.

bint
The second inclusive bound of the random numbers.

nint
The amount of numbers to generate.

Example

# 2-dice roll

<$roll = [rand-list: 1; 6; 2]>
You rolled '[join: \sand\s; <roll>] for a total of '[sum: <roll>].

# ~> You rolled 5 and 3 for a total of 8.

randf


[%randf-list: a; b; n]

list

Prints a list of n random floats with uniform distribution between a (inclusive) and b (exclusive).

Parameters

afloat
The first inclusive bound of the random numbers.

bfloat
The second inclusive bound of the random numbers.

nint
The amount of numbers to generate.

shred


[%shred: input; count; variance]

list

Generates a list of count random numbers, whose sum equals input, and with a maximum absolute difference of variance.

Parameters

inputint | float
The input number to shred.

countint
The number of parts to shred input into.

varianceint | float
The maximum absolute difference between any two generated numbers.

Errors

Raises an error if count is less than 1.

Example

# Generate and print a list of 5 random numbers that add up to 1000
<$parts = [shred:1000;5;200]>
[join:" + ";<parts>] = [sum:<parts>]

##
Output:
170 + 378 + 83 + 189 + 180 = 1000
##