Work
Scaling a uniform draw into a range
The uniform fraction is multiplied by the width of the range and shifted up by the minimum. For integers the fractional part is dropped afterwards.
Last updated
The Formula
value = min + u x (max - min)
The uniform fraction is multiplied by the width of the range and shifted up by the minimum. For integers the fractional part is dropped afterwards.
| Symbol | Meaning | Unit | Notes |
|---|---|---|---|
| u | Uniform draw | fraction | A value in [0, 1) from the generator. |
| min | Minimum | value | The smallest value the draw may return. |
| max | Maximum | value | The largest value the draw may return. |
| v | Drawn value | value | The result shifted into the range. |
What Each Symbol Means
ufraction
Uniform draw
A value in [0, 1) from the generator.
minvalue
Minimum
The smallest value the draw may return.
maxvalue
Maximum
The largest value the draw may return.
vvalue
Drawn value
The result shifted into the range.
See It Worked With Real Numbers
A formula on its own does not tell you which number goes where. The how to generate random numbers page applies this equation to a concrete case, shows every intermediate step, and names the mistakes that produce a wrong answer even when the algebra is right.
Where This Formula Appears
This equation is the working core of How To Generate Random Numbers, filed under Everyday Life. Every number the guide produces comes from substituting into this one line.
Common Questions
What is the formula for Scaling a uniform draw into a range?
The formula for Scaling a uniform draw into a range is value = min + u x (max - min). The uniform fraction is multiplied by the width of the range and shifted up by the minimum. For integers the fractional part is dropped afterwards.
What does each symbol in Scaling a uniform draw into a range stand for?
u is uniform draw; min is minimum; max is maximum; v is drawn value.
What units should I use with Scaling a uniform draw into a range?
Substitute u in fraction, min in value, max in value, v in value. Convert every input to those units before you start, because the equation only returns the right answer when the units on both sides agree.
What is a common mistake when using Scaling a uniform draw into a range?
Using a seeded generator for anything that matters. A fixed seed reproduces the whole sequence, so anyone who knows the seed knows every value in advance. Passwords, tokens, lottery draws and raffles need an operating system entropy source instead.