Difference between revisions of "Rn2"
Jump to navigation
Jump to search
Ray Chason (talk | contribs) (Random variable infobox; prettify the reference) |
Ray Chason (talk | contribs) (Correct formula for mean) |
||
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/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)<ref>{{function|rnd.c|rn2}}</ref> 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). | rn2(x)<ref>{{function|rnd.c|rn2}}</ref> 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). | ||
Revision as of 23:35, 1 February 2011
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) { ... }
See also rn1.
References
- This page is a stub. Should you wish to do so, you can contribute by expanding this page.