Random
Draw random numbers, picks and strings.
Random values follow the run’s seed, so a run can be repeated; see random values and seeds.
randbool
randbool(probability...) → boolReturn true with the given probability (default 0.5).
| Parameter | Type | Description |
|---|---|---|
probability... | number | Chance of true, from 0 to 1. Optional. |
randbool(0.1)→ false
randchoice
randchoice(list) → anyReturn one element of a list, picked at random.
| Parameter | Type | Description |
|---|---|---|
list | list |
randchoice(["eu", "us", "apac"])→ "us"
randfloat
randfloat(min, max) → numberReturn a random number at least min and below max.
| Parameter | Type | Description |
|---|---|---|
min | number | |
max | number |
floor(randfloat(5, 500) * 100) / 100→ 123.45
randhex
randhex(length) → stringReturn a random lowercase hex string of the given length.
| Parameter | Type | Description |
|---|---|---|
length | number |
randhex(12)→ "9f04c1a77be2"
randint
randint(min, max) → numberReturn a random integer between min and max, inclusive.
| Parameter | Type | Description |
|---|---|---|
min | number | Smallest value, an integer. |
max | number | Largest value, an integer. |
randint(1, 6)→ 4
randnormal
randnormal(mean, stddev) → numberReturn a random number from a normal distribution.
Most values land within one stddev of mean; use max/min to clamp the tails.
| Parameter | Type | Description |
|---|---|---|
mean | number | |
stddev | number |
round(randnormal(40, 10))randsample
randsample(list, n) → listReturn n distinct elements of a list, in random order.
| Parameter | Type | Description |
|---|---|---|
list | list | |
n | number | How many elements, at most the list’s length. |
randsample(["a", "b", "c", "d"], 2)→ ["c", "a"]
randshuffle
randshuffle(list) → listReturn a list’s elements in random order.
| Parameter | Type | Description |
|---|---|---|
list | list |
randshuffle([1, 2, 3])→ [3, 1, 2]
randstring
randstring(length, charset...) → stringReturn a random string of the given length.
Characters come from charset, letters and digits by default.
| Parameter | Type | Description |
|---|---|---|
length | number | |
charset... | string | Characters to draw from. Optional. |
randstring(8)→ "q3ZxT0bA"
randstring(6, "0123456789")→ "402913"
randweighted
randweighted(weights) → stringReturn a key of a map, picked with probability proportional to its weight.
| Parameter | Type | Description |
|---|---|---|
weights | map(number) | Keys to choose from, each with a non-negative weight. |
randweighted({ card = 70, paypal = 20, bank = 10 })→ "card"