Difference between revisions of "Rn2"

From NetHackWiki
Jump to navigation Jump to search
(Fix the grammar from a previous copy edit.)
(Fix the grammar from a previous copy edit.)
 
(No difference)

Latest revision as of 01:46, 3 July 2024

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

For example, to simulate a percentage chance:

if (rn2(100) < chance) { ... }

Also,

!rn2(x)

is true with a 1/x probability.

See also rn1.

References