rnl

rnl(x)[1] is a pseudo-random number function used in NetHack when a result should be weighted by Luck.

rnl(x) has the same range as rn2(x) (that is, 0<=rnl(x)<x), but is weighted toward 0 if you have positive Luck, and toward x-1 if you have negative Luck. At Luck levels with similar result distributions (such as 12 and 13 in most cases), the results are sometimes skewed very slighly in reverse (see rnl(3)>0 below).

How it's used

rnl is used for the following purposes:

Situation Code Luck
-13 -5 -2 +3 +6 +9 +12
Whether your god will help if you pray with exactly 0 alignment rnl(2)==0[2] 01% 01% 50% 99% 99% 99% 99%
Chance of writing a scroll you have not seen rnl(15)==0[3] .1% .1% 6.7% 13% 20% 26% 33%
Chance of writing a scroll you have not seen, as a Wizard rnl(3)==0[4] .5% .6% 33.3% 66.0% 98.5% 98.4% 98.2%
Chance to fail to set a landmine (then it blows up) or bear trap (nothing happens) from a horse when riding while unskilled rnl(10)>5[5] 99% 50% 40% 30% 20% 11% 1%
Chance to fail to set a landmine (then it blows up) or bear trap (nothing happens) from a horse when riding while unskilled, while fumbling or with a cursed trap rnl(10)>3[6] 99% 70% 60% 50% 40% 31% 21%
Chance that a trap goes off after you set it, if it was cursed or you fumbled rnl(10)>5[7] 99% 50% 40% 30% 20% 11% 1%
Chance that an otherwise pickup-able object does not slip free when you use a whip to pick it up rnl(6)==0[8] 0.3% 0.3% 16.7% 33.0% 49.2% 65.4% 81.6%
Chance of finding secret corridors and doors on each surrounding square when searching rnl(7)==0[9] 0% 0% 14% 28% 42% 56% 70%
Chance of finding secret corridors and doors on each surrounding square when searching, while wearing lenses rnl(5)==0[10] 0% 0% 20% 40% 59% 79% 98%
Chance of finding secret corridors and doors on each surrounding square when searching, while wielding a +5 Excalibur, or +3 Excalibur and lenses, or any better combination rnl(2)==0[11] 1% 1% 50% 99% 99% 99% 99%
Chance of finding a hidden trap when searching rnl(8)==0[12] 0% 0% 12% 25% 37% 49% 61%
Chance that a blessed projectile is not broken when thrown rnl(4)==0[13] .4% .5% 25.0% 49.5% 73.9% 98.2% 98.0%
Chance that you are petrified if your saddle slips off[14] or is detroyed(?), or you are polymorphed and lose stone resistance[15], and are riding a steed that petrifies on touch (likely due to your horse having just polymorphed into a footrice) rnl(3)>0 99.5% 99.4% 66.7% 34.0% 1.5% 1.6% 1.8%
Chance of a random levelport when attempting to controlled levelport (or cancel) while confused rnl(5)>0[16] 99.7% 99.6% 80.0% 60.4% 40.9% 21.5% 2.1%
Chance that blessed equipment is not eroded by rust[17] or water[18] damage, or blessed flammable items are not burned by fire damage[19] rnl(4)==0 .4% .5% 25.0% 49.5% 73.9% 98.2% 98.0%
Chance that a monster becomes angry when it steps in a trap set by you[20], or that you trigger a trap when failing to disarm it[21] rnl(5)>0 99.7% 99.6% 80.0% 60.4% 40.9% 21.5% 2.1%
Chance that a hostile, awake, unfrozen, mindful, nonhuman monster becomes peaceful when you free it from a trap not set by you (more steps in distribution) rnl(10)<8[22] 1% 70% 80% 90% 100% 100% 99%
Chance that a lawful player gets +1 alignment for the above rnl(8)==0 times 1/3[23] 0% 0% 4% 8% 12% 16% 20%
Chance that you get +1 alignment for trying and failing to lift a hostile, mobile, mindful, nonhuman monster out of a pit not dug by you rnl(10)<3[24] 0% 20% 30% 40% 50% 59% 69%
Chance that a boomerang will break when used as a melee weapon rnl(4)==3[25] 99% 50% 25% 1% 1% 1% 1%
Chance that a successful joust, against a solid monster, breaks your non-artifact lance (very smooth distribution, 28% at Luck -13, 2% at Luck 0, .04% at Luck 1) rnl(50)==49[26] 27.59% 11.82% 5.92% .04% .05% .05% .05%
Probability based on non-Luck stats
Chance that you can kick down a door (somewhat smooth distribution) rnl(35)<X where X = avg( str, dex, con) + (dex if Samurai or Monk)[27] Approx ((Luck+X)*2.9)+.1% for negative luck, 99.9-((35-(Luck+X))*2.9)% for positive luck[28]
Chance that you can kick down a door, avg(str,dex,con)=10 rnl(35)<10 0.5% 14.5% 23.0% 37.0% 45.3% 53.7% 62.0%
Chance that you can kick down a door, avg(str,dex,con)=15 rnl(35)<15 6% 29% 37% 51% 60% 68% 76%
Chance that you can kick down a door, Samurai or Monk and avg(str,con)=15, dex=15 rnl(35)<20 21% 43% 52% 66% 74% 82% 91%
Chance that you can open a door (smoother distribution) rnl(20)<X where X = avg( str, dex, con)[29] Approx ((Luck+X)*5)+.1% for negative luck, 99.9-((20-(Luck+X))*5)% for positive luck[30]
Chance that you can open a door, avg(str,dex,con)=10 rnl(20)<10 1% 25% 40% 65% 79% 94% 99%
Chance that you can open a door, avg(str,dex,con)=15 rnl(20)<15 11% 50% 65% 90% 99% 99% 99%
One criterion (the other being alignment-based) for an altar conversion[31] (or attempt[32]) producing a summoned minion. rnl(your level)>6 Impossible before level 8, more likely with low luck, more likely at higher level
Chance of summoning a minion, all other criteria being met, at level 8 rnl(8)>6 98.6% 24.8% 12.5% 0.3% 0.3% 0.3% 0.3%
Chance of summoning a minion, all other criteria being met, at level 12 (smoother distribution) rnl(12)>6 99% 50% 42% 34% 25% 17% 9%
Chance of summoning a minion, all other criteria being met, at level 16 (smoother distribution) rnl(16)>6 99% 87% 69% 38% 20% 1% 1%
Chance of summoning a minion, all other criteria being met, at level 24 (smoother distribution) rnl(24)>6 100% 91% 79% 59% 46% 34% 22%
Chance of angering your god by praying in Gehennom rnl(alignment)>0[33] Certain with negative alignment, impossible at alignment 1 (!), more likely with higher alignment, less likely with higher luck
Chance of angering your god by praying in Gehennom at alignment 2 rnl(2)>0 99% 99% 50% 1% 1% 1% 1%
Chance of angering your god by praying in Gehennom at alignment 4 rnl(4)>0 100% 100% 75% 51% 26% 2% 2%
Chance of angering your god by praying in Gehennom at alignment 8 rnl(8)>0 100% 100% 88% 75% 63% 51% 39%
Chance of angering your god by praying in Gehennom at alignment 16 (smoother distribution) rnl(16)>0 100% 100% 100% 75% 57% 39% 21%
Chance of angering your god by praying in Gehennom at alignment 32 (smoother distribution) rnl(32)>0 100% 100% 100% 88% 79% 69% 60%
Numerical Distributions
Average number of fruit that fall from a tree if you kick it and are otherwise lucky 8-rnl(7)[34] 2 4.2 5.0 5.8 6.5 7.1 7.5
Average number of bees that fall from a tree if you kick it and are otherwise unlucky rnl(4)+2[35] 5.0 4.2 3.5 2.8 2.3 2.0 2.0
Amount of gold left from a gold golem's death (average, smooth distribution) 200-rnl(101)[36] 138 145 148 153 156 158 161
Number of darts/arrows/etc left behind when disarming a trap (average, smooth distribution) 50-rnl(50)[37] 14 21 24 28 31 33 36

Some very high (99.8%) and very low (0.2%) values above are rounded to 100% or 0%. Nothing is completely 100% or 0% likely, except where spelled out as "certain" or "impossible". Comments on the distribution indicate that there is less than the normal stair-step quality, such that Luck -6 may not be as bad as Luck -13, or Luck +8 may be better than Luck +6, etc.

Mathematical analysis

rnl, while not even in the same league as rnz, accomplishes its goal (weighting a random number according to luck) in a non-straightforward way. As luck becomes more positive or negative, more high or low numbers on the list become vanishingly unlikely, and the odds of getting the best or worst result increase, while the odds of getting every result in between stays the same.

This leads to a stair step effect in the distribution when the parameter is low, usually with large improvements at -5, -2, 3, 6, 9, and 12, and no improvement (or even very slight decrease in the luckiness of the outcome) in between. With larger parameters the distribution becomes more smooth, as evidenced in the above explanations for the chances to kick down or open a door.

With lower parameters, there is a bias towards unluckiness. Unlucky results become unlikely at high Luck less quickly than lucky results become unlikely at low Luck.

Also, there is another very slight bias towards unluckiness. Where subsets of the distribution are symmetric at a high level, the very small chances of a great result with bad luck are about 60% of the almost-as-small chances of a horrible result with good luck. This accounts for numerous situations in which 12, or even 6, Luck is better than 13.

This is complicated by the function often being called in unusual manners, such as comparing it to a non-zero constant, which results in a "slice" being taken from the distribution graph at a less easily explainable point. This is evidenced in the distrubtions for rnl(A)<B or rnl(A)>B above.

The overall "smoothest" way to use this function is rnl(A)<(A/2), as this takes into account both of the major patterns in the distribution. This is similar to the door opening function at typical stat levels.

Sample Distribution

This table is a monte carlo simulation of rnl(10) run one million times at each possible luck, and the frequency of each result. The 00% at negative Luck are 0.16% while the 00% at positive Luck are 0.25%.

Luck Simplified Results
0 1 2 3 4 5 6 7 8 9
-13 00% 00% 00% 00% 00% 00% 00% 00% 00% 98%
-12 00% 00% 00% 00% 00% 00% 00% 00% 00% 98%
-11 00% 00% 00% 00% 00% 00% 00% 00% 00% 98%
-10 00% 00% 00% 00% 00% 00% 00% 00% 00% 98%
-9 00% 00% 00% 00% 00% 00% 00% 00% 00% 98%
-8 00% 00% 00% 00% 00% 00% 00% 00% 10% 88%
-7 00% 00% 00% 00% 00% 00% 00% 10% 10% 78%
-6 00% 00% 00% 00% 00% 00% 10% 10% 10% 68%
-5 00% 10% 10% 10% 10% 10% 10% 10% 10% 19%
-4 00% 10% 10% 10% 10% 10% 10% 10% 10% 19%
-3 00% 10% 10% 10% 10% 10% 10% 10% 10% 19%
-2 10% 10% 10% 10% 10% 10% 10% 10% 10% 10%
-1 10% 10% 10% 10% 10% 10% 10% 10% 10% 10%
0 10% 10% 10% 10% 10% 10% 10% 10% 10% 10%
1 10% 10% 10% 10% 10% 10% 10% 10% 10% 10%
2 10% 10% 10% 10% 10% 10% 10% 10% 10% 10%
3 19% 10% 10% 10% 10% 10% 10% 10% 10% 00%
4 19% 10% 10% 10% 10% 10% 10% 10% 10% 00%
5 19% 10% 10% 10% 10% 10% 10% 10% 10% 00%
6 29% 10% 10% 10% 10% 10% 10% 10% 00% 00%
7 29% 10% 10% 10% 10% 10% 10% 10% 00% 00%
8 29% 10% 10% 10% 10% 10% 10% 10% 00% 00%
9 39% 10% 10% 10% 10% 10% 10% 00% 00% 00%
10 39% 10% 10% 10% 10% 10% 10% 00% 00% 00%
11 39% 10% 10% 10% 10% 10% 10% 00% 00% 00%
12 49% 10% 10% 10% 10% 10% 00% 00% 00% 00%
13 49% 10% 10% 10% 10% 10% 00% 00% 00% 00%