Difference between revisions of "Rn2"
Jump to navigation
Jump to search
(lede) |
(nethack-366 -> nethack-367. Also fix an unversioned function reference.) |
||
Line 1: | Line 1: | ||
{{DISPLAYTITLE:rn2}} | {{DISPLAYTITLE:rn2}} | ||
{{randomvariable|name=rn2(x)|graph=rn2.svg|caption=[[wikipedia:Probability mass function|Probability mass function]] of rn2(10).|distribution=[[Wikipedia:discrete uniform distribution|uniform]]|mean=<math>(x-1)/2</math>|stddev=<math>\sqrt{(x^2-1)/12}</math>}} | {{randomvariable|name=rn2(x)|graph=rn2.svg|caption=[[wikipedia:Probability mass function|Probability mass function]] of rn2(10).|distribution=[[Wikipedia:discrete uniform distribution|uniform]]|mean=<math>(x-1)/2</math>|stddev=<math>\sqrt{(x^2-1)/12}</math>}} | ||
− | '''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) < x). | + | '''rn2(x)''' is a pseudo-random number function used in the code of ''[[NetHack]]''.{{refsrc|nethack=3.6.7|src/rnd.c|99}} 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) < x). |
For example, to simulate a percentage chance: | For example, to simulate a percentage chance: | ||
Line 14: | Line 14: | ||
==References== | ==References== | ||
<references/> | <references/> | ||
− | {{nethack- | + | {{nethack-367}} |
[[Category:Random number functions]] | [[Category:Random number functions]] |
Revision as of 01:43, 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": 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.