# rn2

rn2(x)

 Probability mass function of rn2(10).

Distribution
uniform

Mean

Standard deviation

rn2(x) is a pseudo-random number function used in the code of NetHack. The function's purpose is to provide an "unweighted": the range of values is between 0 and x-1 inclusive (that is, 0 ≤ rn2(x) &lt; x).[1]
For example, to simulate a percentage chance:

if (rn2(100) &lt; chance) { ... }

Also,

!rn2(x)

is true with a 1/x probability.
See also rn1.

References

↑ rn2 in rnd.c