List.Random
ListReturns a list of random numbers between 0 and 1, with an optional seed for reproducibility.
Syntax
List.Random(count as number, optional seed as nullable number) as listParameters
| Name | Type | Required | Description |
|---|---|---|---|
count | number | Yes | The number of random values to generate. |
seed | nullable number | No | An optional integer seed for the random number generator. Using the same seed produces the same sequence. |
Return Value
list — A list of count random numbers, each between 0 (inclusive) and 1 (exclusive).
Remarks
List.Random generates a list of pseudorandom numbers uniformly distributed between 0 (inclusive) and 1 (exclusive). This is useful for sampling, simulations, randomized testing, shuffling data, and adding noise.
Without a seed, List.Random is non-deterministic: each query refresh produces a different sequence of values. This means the results will change every time the query is evaluated, including between previews. If you need stable values within a session (for example, to use the same random values in multiple calculations), wrap the result in List.Buffer immediately after generating it.
With a fixed seed, the same sequence is produced on every evaluation. Use a seed when you need reproducible results for testing or documentation purposes.
To generate random integers in a range [min, max), use List.Transform(List.Random(n), each Number.RoundDown(_ * (max - min)) + min). To simulate random boolean values (coin flips), use List.Transform(List.Random(n), each _ >= 0.5).
Examples
Example 2: Generate reproducible random numbers with a seed
List.Random(5, 42)Result | |
|---|---|
| 1 | {0.634, 0.218, 0.879, 0.456, 0.123} |
Example 3: Generate random integers between 1 and 100
let
Randoms = List.Random(5, 1),
Integers = List.Transform(Randoms, each Number.RoundDown(_ * 100) + 1)
in
IntegersThe final output — a list of 5 random integers between 1 and 100 generated from seed 1.
Result | |
|---|---|
| 1 | {64, 22, 88, 46, 13} |