Math
RANDBETWEEN and RAND: generate bounded integer and decimal test samples
Create synthetic QA datasets with inclusive integer RANDBETWEEN(bottom, top) and continuous [0, 1) RAND() scaling.
Inclusive integers vs continuous decimals
RANDBETWEEN(bottom, top) returns a uniformly distributed whole integer n such that bottom <= n <= top (both endpoints included).
RAND() takes no arguments and returns a continuous decimal x where 0 <= x < 1. To generate random decimals between Min (A2) and Max (B2), write A2 + (B2 - A2) * RAND().
| MinBound (A) | MaxBound (B) | Integer Formula | Continuous Decimal Formula |
|---|---|---|---|
| 100 | 250 | =RANDBETWEEN(A2, B2) | =A2 + (B2 - A2) * RAND() |
Verify range and integer invariants with LET
Capturing a single draw inside LET(draw, RANDBETWEEN(A2, B2), AND(draw>=A2, draw<=B2, INT(draw)=draw)) tests the exact same random draw against all three bounds—avoiding the classic bug of calling RANDBETWEEN twice in one IF statement (which draws two different numbers!).
=LET(draw, RANDBETWEEN(A2, B2), AND(draw>=A2, draw<=B2, INT(draw)=draw))Equal bounds and bottom > top guard
When bottom equals top (RANDBETWEEN(100, 100)), the output is deterministically 100. Always ensure bottom <= top with IF(A2>B2, "Min > Max", RANDBETWEEN(A2, B2)).
=RANDBETWEEN(100, 100)Try the example
Use the original values or change them to test your understanding.