Difference between revisions of "Rn2"

From NetHackWiki
Jump to navigation Jump to search
(I don't think there's been any real changes to this...)
Line 14: Line 14:
 
==References==
 
==References==
 
<references/>
 
<references/>
 
+
{{nethack-366}}
 
[[Category:Random number functions]]
 
[[Category:Random number functions]]
{{nethack-343}}
 

Revision as of 03:32, 27 February 2022

rn2(x)[1] is a pseudo-random number function used in NetHack when a result should be unweighted. 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