List.Random
A list of random numbers from 0 up to 1, new ones on each run unless you give a seed.
Group: List. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
List.Random(count as number, optional seed as nullable number) as list
| Parameter | Type | Description |
|---|---|---|
count | number | How many numbers; 0 gives an empty list, a negative count an error. |
seed | nullable number optional | A whole number that fixes the sequence: the same seed gives the same numbers on every run. Left out, the numbers are new each time. |
Returns
list. The numbers, each at least 0 and below 1.
Remarks
- A seed gives the very numbers Power Query gives for it, so test data made with one is the same in Power BI Desktop and in OpenBI.
- The seed must fit a 32-bit whole number: a fraction or a larger number is an error.
Compared with Power Query
Known difference in OpenBI Studio 0.3.79, found while this page was written and run on its engine:
List.Count(List.Distinct(Table.AddColumn(#table({"Order"}, {{1}, {2}, {3}}), "R", each List.Random(1){0})[R])): Power Query gives 1: in a column added withTable.AddColumn, every row gets the same random number, and the model loads it so. OpenBI gives each row its own: 3.
Examples
Three random numbers
List.Random(3)
{0.5855880213458295, 0.689108742296363, 0.4947729704486352}
The same three numbers on every run
List.Random(3, 42)
{0.6681064659115423, 0.14090729837348093, 0.12551828945312568}
Dice rolls for a test table
List.Transform(List.Random(3, 7), each Number.RoundDown(_ * 6) + 1)
{3, 6, 4}
Each number times 6, rounded down, plus 1: a whole number from 1 to 6.
Related functions
Number.Random, Number.RandomBetween, List.Numbers, List.Transform.