RANDBETWEEN
A random whole number between two numbers, both included, different at each evaluation.
Group: Math. Compatible with DAX.
Syntax
RANDBETWEEN ( <bottom>, <top> )
| Parameter | Type | Description |
|---|---|---|
bottom | Whole number | The smallest number that may come out. |
top | Whole number | The largest number that may come out; not below bottom. |
Returns
Whole number. A random whole number from bottom to top, both included.
Remarks
- Every call draws again, each row of a table included, and the results change whenever the query runs again.
- A bottom above the top is an error. With bottom equal to top, that number is the answer.
- A bound with decimals is taken inwards: the bottom rounded up, the top down. From 1.5 to 2.4 the only whole number is 2; from 1.2 to 1.9 there is none, and that is an error.
- Each whole number in the range is equally likely.
Examples
A roll of a die
Your result will differ.
EVALUATE
ROW ( "Die", RANDBETWEEN ( 1, 6 ) )
| Die |
|---|
| 3 |
Five rolls
EVALUATE
ADDCOLUMNS ( GENERATESERIES ( 1, 5 ), "Roll", RANDBETWEEN ( 1, 6 ) )
| Value | Roll |
|---|---|
| 1 | 1 |
| 2 | 3 |
| 3 | 2 |
| 4 | 2 |
| 5 | 4 |
Bounds that leave one number
Equal bounds, and bounds with decimals that leave only 2 between them.
EVALUATE
ROW ( "From 5 to 5", RANDBETWEEN ( 5, 5 ), "From 1.5 to 2.4", RANDBETWEEN ( 1.5, 2.4 ) )
| From 5 to 5 | From 1.5 to 2.4 |
|---|---|
| 5 | 2 |