Difference between revisions of "Rnl"

From NetHackWiki
Jump to navigation Jump to search
m (How it's used: "chance to" = opportunity; "chance of" = probability)
(untrapping can specifically pacify non-@, not non-human)
 
(7 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 
{{DISPLAYTITLE:rnl}}
 
{{DISPLAYTITLE:rnl}}
'''rnl(x)'''<ref name=main>{{function|rnd.c|rnl}}</ref> is a pseudo-random number function used in NetHack when a result should be weighted by [[Luck]].
+
{{distinguish|rn1}}
 +
'''rnl(<var>x</var>)'''{{refsrc|src/rnd.c|116|nethack=3.6.6|name=main}} 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&lt;=rnl(x)&lt;x), but is weighted toward 0 if you have positive Luck, and toward x-1 if you have negative Luck.
+
rnl(<var>x</var>) has the same range as rn2(<var>x</var>) (that is, 0&nbsp;&le; rnl(<var>x</var>)&nbsp;&lt;&nbsp;<var>x</var>), but is weighted toward 0 if you have positive Luck, and toward <var>x</var>&nbsp;&minus;&nbsp;1 if you have negative Luck.
  
 
== Formula ==
 
== Formula ==
Line 8: Line 9:
 
See source code in <ref name=main/>
 
See source code in <ref name=main/>
  
Let R be a random integer number from 0 to x-1 (inclusively).
+
For rnl(<var>x</var>), let <var>L</var> equal your Luck, including the [[luck item]] bonus or penalty, whether positive, negative, or zero.
  
If Luck=0, R is returned.
+
If <var>x</var> &le; 15, <var>L</var> = {{frac|<var>L</var>|3}}, rounded toward the nearest integer.
  
Otherwise, let A be
+
If <var>L</var> = 0, return [[rn2]](<var>x</var>).
* Luck/3 rounded to the closest integer, if x<=15 (note that in this case A is from -4 to 4)
 
* Luck, otherwise
 
  
If A=0, R is returned.
+
With chance {{sfrac|1|37 + {{!}}<var>L</var>{{!}}}}, return rn2(<var>x</var>).
  
Otherwise, with chance 1/(37+|A|), R is still returned (note that the chance is always between 1/38 and 1/50).
+
Otherwise, return rn2(<var>x</var>) - <var>L</var>, but no less than 0 and no more than <var>x</var> - 1.
  
Otherwise, R-A is forced into [0,x-1] interval and returned.
+
This means that rnl(<var>x</var>) is almost always equivalent to rn2(<var>x</var>) - Luck when <var>x</var> > 15. The chance of Luck being ignored is less than 3% in any case, and even smaller for stronger (positive or negative) Luck. For smaller values of <var>x</var>, rn2(<var>x</var>) - {{sfrac|Luck|3}} is the most likely approximation.
  
Note this means that for Luck in [-1,1] interval and x<=15, rnl just returns a random integer in the [0,x-1] interval (because A=0). For Luck of -2 or worse, however, rnl has a tiny chance of returning 0 (between 1/(38*x) and 1/(50*x), depending on Luck).  For Luck of 2 or better, the chance of returning 0 increases significantly.  For example, if x=10, the chance will be 10% for Luck between -1 and 1, about 20% for Luck of 2 to 4, and about 49% for Luck of 11 to 13.
+
== How it's used ==
 
 
=== Historical ===
 
 
 
In 3.4.3, the formulas were slightly different<ref>[https://nethackwiki.com/wiki/Source:NetHack_3.4.3/src/rnd.c#rnl rnl in rnd.c for Nethack 3.4.3]</ref>
 
 
 
Let R be a random integer number from 0 to x-1 (inclusively).
 
 
 
If Luck=0, R is returned.
 
 
 
Otherwise, with 1/(50-Luck) chance (since Luck is from -13 to 13, the chance should be between 1/37 and 1/63), R is returned.
 
 
 
Otherwise, if x<=15 and Luck>=-5 (that is, x is not too big and the user is not too unlucky), Luck/3 (truncated towards zero) is subtracted from R, than R is forced into the [0,x-1] interval.
 
  
Otherwise, Luck is subtracted from R, after which R is forced into the [0,x-1] interval and returned.
+
In the tables below, 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".
 
 
== How it's used ==
 
  
rnl is used for the following purposes:
+
=== Events based solely on Luck ===
  
 
{| class="wikitable"
 
{| class="wikitable"
!Situation!!Code!!colspan="9"|Luck
+
!rowspan=2|Situation !! rowspan=2|Code !! colspan=9|Luck
 
|-
 
|-
| || ||-11||-8||-5||-2||0||+2||+5||+8||+11
+
!&minus;11 !! &minus;8 !! &minus;5 !! &minus;2 !! 0 !! +2 !! +5 !! +8 !! +11
 
|-
 
|-
| Whether your god will help if you pray with exactly 0 alignment || rnl(2)==0{{refsrc|pray.c|828}} || 01% || 01% || 01% || 01% || 50% || 99% || 99% || 99% || 99%
+
| Chance of your god helping you if you [[pray]] with exactly 0 [[alignment record|alignment]]
 +
| <code>rnl(2)==0</code>{{refsrc|pray.c|828}}
 +
| 1% || 1% || 1% || 1% || 50% || 99% || 99% || 99% || 99%
 
|-
 
|-
| Chance of writing a scroll you have not seen || rnl(15)==0{{refsrc|write.c|201}} || .2% || .2% || .2% || .2% || 6.7% || 13.2% || 19.7% || 26.2% || 32.7%
+
| Chance of [[Magic marker|writing]] a scroll you have not seen
 +
| <code>rnl(15)==0</code>{{refsrc|write.c|201}}
 +
| 0.2% || 0.2% || 0.2% || 0.2% || 6.7% || 13.2% || 19.7% || 26.2% || 32.7%
 
|-
 
|-
| Chance of writing a scroll you have not seen, as a Wizard || rnl(3)==0{{refsrc|write.c|201}} || .8% || .8% || .9% || .9% || 33.3% || 65.8% || 98.3% || 98.3% || 98.3%
+
| Chance of [[Magic marker|writing]] a scroll you have not seen, as a [[Wizard]]
 +
| <code>rnl(5)==0</code>{{refsrc|write.c|201}}
 +
| 0.5% || 0.5% || 0.5% || 0.5% || 20.0% || 39.5% || 59.0% || 78.5% || 98.0%
 
|-
 
|-
| Chance of failing to set a landmine (in which case it blows up) or bear trap (nothing happens) from a horse when riding while unskilled || rnl(10)>5{{refsrc|apply.c|2034}} || 79% || 69% || 59% || 50% || 40% || 30% || 21% || 11% || 1%
+
| Chance of failing to set a [[land mine]] (in which case it blows up) or [[beartrap]] (nothing happens) while [[riding]] and [[Skill|unskilled]] at riding
 +
| <code>rnl(10)>5</code>{{refsrc|apply.c|2034}}
 +
| 79% || 69% || 59% || 50% || 40% || 30% || 21% || 11% || 1%
 
|-
 
|-
| Chance of failing to set a landmine (in which case 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{{refsrc|apply.c|2034}} || 99% || 89% || 79% || 70% || 60% || 50% || 41% || 31% || 21%
+
| Chance of failing to set a [[land mine]] (in which case it blows up) or [[beartrap]] (nothing happens) while [[riding]] and [[Skill|unskilled]] at riding, and [[fumbling]] or using a cursed trap
 +
| <code>rnl(10)>3</code>{{refsrc|apply.c|2034}}
 +
| 99% || 89% || 79% || 70% || 60% || 50% || 41% || 31% || 21%
 
|-
 
|-
| Chance that a trap goes off after you set it, if it was cursed or you fumbled || rnl(10)>5{{refsrc|apply.c|2097}} || 79% || 69% || 59% || 50% || 40% || 30% || 21% || 11% || 1%
+
| Chance that a trap goes off after you set it, if it was cursed or you were [[fumbling]]
 +
| <code>rnl(10)>5</code>{{refsrc|apply.c|2097}}
 +
| 79% || 69% || 59% || 50% || 40% || 30% || 21% || 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{{refsrc|apply.c|2174}} || 0.4% || 0.4% || 0.4% || 0.4% || 16.7% || 32.9% || 49.1% || 65.4% || 81.8%
+
| Chance of snagging an item you can pick up when using a [[bullwhip]] (instead of having it slip free)
 +
| <code>rnl(6)==0</code>{{refsrc|apply.c|2174}}
 +
| 0.4% || 0.4% || 0.4% || 0.4% || 16.7% || 32.9% || 49.1% || 65.4% || 81.8%
 
|-
 
|-
| Chance of finding secret corridors and doors on each surrounding square when searching || rnl(7)==0{{refsrc|detect.c|1191}} || 0.3% || 0.4% || 0.4% || 0.4% || 14.3% || 28.2% || 42.1% || 56.1% || 70.0%
+
| Chance of finding [[secret passage]]s and [[Secret door|doors]] on each surrounding square when [[search]]ing
 +
| <code>rnl(7)==0</code>{{refsrc|detect.c|1191}}
 +
| 0.3% || 0.4% || 0.4% || 0.4% || 14.3% || 28.2% || 42.1% || 56.1% || 70.0%
 
|-
 
|-
| Chance of finding secret corridors and doors on each surrounding square when searching, while wearing [[lenses]] || rnl(5)==0{{refsrc|detect.c|1183}} || 0.5% || 0.5% || 0.5% || 0.5% || 20.0% || 39.5% || 59.0% || 78.5% || 98.0%
+
| Chance of finding [[secret passage]]s and [[Secret door|doors]] on each surrounding square when [[search]]ing, while wearing a [[pair of lenses]]
 +
| <code>rnl(5)==0</code>{{refsrc|detect.c|1183}}
 +
| 0.5% || 0.5% || 0.5% || 0.5% || 20.0% || 39.5% || 59.0% || 78.5% || 98.0%
 
|-
 
|-
| 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{{refsrc|detect.c|1183}} || 1.2% || 1.3% || 1.3% || 1.3% || 50% || 98.7% || 98.7% || 98.8% || 98.8%
+
| Chance of finding [[secret passage]]s and [[Secret door|doors]] on each surrounding square when [[search]]ing,  while wielding a +5 [[Excalibur]], or +3 Excalibur and lenses, or any better combination
 +
| <code>rnl(2)==0</code>{{refsrc|detect.c|1183}}
 +
| 1.2% || 1.3% || 1.3% || 1.3% || 50% || 98.7% || 98.7% || 98.8% || 98.8%
 
|-
 
|-
| Chance of finding a hidden trap when searching || rnl(8)==0{{refsrc|detect.c|1248}} || 0.3% || 0.3% || 0.3% || 0.3% || 12.5% || 24.7% || 36.9% || 49.1% || 61.3%
+
| Chance of finding a hidden [[trap]] when [[search]]ing
 +
| <code>rnl(8)==0</code>{{refsrc|detect.c|1248}}
 +
| 0.3% || 0.3% || 0.3% || 0.3% || 12.5% || 24.7% || 36.9% || 49.1% || 61.3%
 
|-
 
|-
| Chance that a blessed projectile is not broken when thrown || rnl(4)==0{{refsrc|dothrow.c|1332}} || 0.6% || 0.6% || 0.6% || 0.7% || 25% || 49.3% || 73.7% || 98.1% || 98.2%
+
| Chance of a blessed [[projectile]] <em>not</em> breaking when thrown
 +
| <code>rnl(4)==0</code>{{refsrc|dothrow.c|1332}}
 +
| 0.6% || 0.6% || 0.6% || 0.7% || 25% || 49.3% || 73.7% || 98.1% || 98.2%
 
|-
 
|-
| Chance that you are petrified if your saddle slips off{{refsrc|worn.c|741}} or is detroyed(?), or you are polymorphed and lose stone resistance{{refsrc|polyself.c|485}}, and are riding a steed that petrifies on touch (likely due to your horse having just polymorphed into a footrice) || rnl(3)>0 || 99.2% || 99.2% || 99.1% || 99.1% || 66.7% || 34.2% || 1.7% || 1.7% || 1.6%
+
| Chance of being [[stoning|petrified]] if your [[saddle]] slips off{{refsrc|worn.c|741}} or is destroyed<!-- verify -->, or you are polymorphed and lose stone resistance,{{refsrc|polyself.c|485}} when you are riding a steed that petrifies on touch (likely due to your horse having just polymorphed into a [[cockatrice]])
 +
| <code>rnl(3)>0</code>
 +
| 99.2% || 99.2% || 99.1% || 99.1% || 66.7% || 34.2% || 1.7% || 1.7% || 1.6%
 
|-
 
|-
| Chance of a random levelport when attempting to controlled levelport (or cancel) while confused || rnl(5)>0{{refsrc|teleport.c|606}} || 99.5% || 99.5% || 99.5% || 99.5% || 80.0% || 60.5% || 41.0% || 21.5% || 2.0%
+
| Chance of a random [[levelport]] when attempting to [[teleport control|controlled]] levelport (or cancel) while [[confused]]
 +
| <code>rnl(5)>0</code>{{refsrc|teleport.c|606}}
 +
| 99.5% || 99.5% || 99.5% || 99.5% || 80.0% || 60.5% || 41.0% || 21.5% || 2.0%
 
|-
 
|-
| Chance that blessed equipment is not eroded by rust{{refsrc|trap.c|162}} or water{{refsrc|trap.c|2735}} damage, or blessed flammable items are not burned by fire damage{{refsrc|trap.c|2666}} || rnl(4)==0 || 0.6% || 0.6% || 0.6% || 0.7% || 25% || 49.3% || 73.7% || 98.1% || 98.2%
+
| Chance of blessed equipment <em>not</em> being eroded by rust{{refsrc|trap.c|162}} or water{{refsrc|trap.c|2735}} damage, or blessed flammable items not being burned by fire damage{{refsrc|trap.c|2666}}
 +
| <code>rnl(4)==0</code>
 +
| 0.6% || 0.6% || 0.6% || 0.7% || 25% || 49.3% || 73.7% || 98.1% || 98.2%
 
|-
 
|-
| Chance that a monster becomes angry when it steps in a trap set by you{{refsrc|trap.c|1716}}, or that you trigger a trap when failing to disarm it{{refsrc|trap.c|3122}} || rnl(5)>0 || 99.5% || 99.5% || 99.5% || 99.5% || 80.0% || 60.5% || 41.0% || 21.5% || 2.0%
+
| Chance of a monster becoming angry when it steps in a trap set by you,{{refsrc|trap.c|1716}} or of you triggering a trap when failing to disarm it{{refsrc|trap.c|3122}}
 +
| <code>rnl(5)>0</code>
 +
| 99.5% || 99.5% || 99.5% || 99.5% || 80.0% || 60.5% || 41.0% || 21.5% || 2.0%
 
|-
 
|-
| Chance that a hostile, awake, unfrozen, mindful, nonhuman monster becomes peaceful when you free it from a trap not set by you || rnl(10)<8{{refsrc|trap.c|3166}} || 40.1% || 50.8% || 60.5% || 70.3% || 80.0% || 89.7% || 99.5% || 99.5% || 99.5%
+
| Chance of a hostile, awake, unfrozen, mindful, non-{{monclasssym|@}} monster becoming peaceful when you free it from a trap not set by you
 +
| <code>rnl(10)<8</code>{{refsrc|trap.c|3166}}
 +
| 40.1% || 50.8% || 60.5% || 70.3% || 80.0% || 89.7% || 99.5% || 99.5% || 99.5%
 
|-
 
|-
| Chance that a lawful player gets +1 alignment for the above || rnl(8)==0 times 1/3{{refsrc|trap.c|3176}} || 0.1% || 0.1% || 0.1% || 0.1% || 4.2% || 8.2% || 12.3% || 16.4% || 20.4%
+
| Chance of a lawful player getting +1 [[alignment record|alignment]] for the above
 +
| <code>rnl(8)==0</code>, one-third of the time{{refsrc|trap.c|3176}}
 +
| 0.1% || 0.1% || 0.1% || 0.1% || 4.2% || 8.2% || 12.3% || 16.4% || 20.4%
 
|-
 
|-
| 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{{refsrc|trap.c|3294}} || 0.7% || 0.8% || 10.5% || 20.2% || 30% || 39.7% || 49.5% || 59.3% || 69.0%
+
| Chance of getting +1 [[alignment record|alignment]] for trying and failing to lift a hostile, mobile, mindful, nonhuman monster out of a pit not dug by you
 +
| <code>rnl(10)<3</code>{{refsrc|trap.c|3294}}
 +
| 0.7% || 0.8% || 10.5% || 20.2% || 30% || 39.7% || 49.5% || 59.3% || 69.0%
 
|-
 
|-
| Chance that a boomerang will break when used as a melee weapon || rnl(4)==3{{refsrc|uhitm.c|587}} || 98.2% || 98.1% || 73.7% || 49.3% || 25% || 0.7% || 0.6% || 0.6% || 0.6%
+
| Chance of having a [[boomerang]] break when used as a melee weapon
 +
| <code>rnl(4)==3</code>{{refsrc|uhitm.c|587}}
 +
| 98.2% || 98.1% || 73.7% || 49.3% || 25% || 0.7% || 0.6% || 0.6% || 0.6%
 
|-
 
|-
| Chance that a successful joust, against a solid monster, breaks your non-artifact lance (very smooth distribution, 4.7% at Luck -13, .01% at Luck 1) || rnl(50)==49, 1/5 of the time{{refsrc|uhitm.c|1153}} || 4.71% || 3.53% || 2.35% || 1.18% || 0.4% || 0.01% || 0.01% || 0.01% || 0.01%
+
| Chance of having a non-artifact [[lance]] break when successfully jousting a solid monster
 +
| <code>rnl(50)==49</code>, {{frac|5}} of the time{{refsrc|uhitm.c|1153}}
 +
| 4.71% || 3.53% || 2.35% || 1.18% || 0.4% || 0.01% || 0.01% || 0.01% || 0.01%
 +
|}
 +
 
 +
=== Events based on Luck and other stats ===
 +
 
 +
{| class="wikitable"
 +
!rowspan=2|Situation !! rowspan=2|Code !! colspan=9|Luck
 
|-
 
|-
|colspan="11"|Probability based on non-Luck stats
+
!&minus;11 !! &minus;8 !! &minus;5 !! &minus;2 !! 0 !! +2 !! +5 !! +8 !! +11
 
|-
 
|-
| 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]]){{refsrc|dokick.c|1046}} || colspan="9"| Approx (Luck+x)/35 chance<ref>computed numbers slightly incorrect</ref>
+
| Chance of kicking down a door
 +
| <code>rnl(35)<X</code>, where X = avg(str, dex, con) + (dex if [[Samurai]] or [[Monk]]){{refsrc|dokick.c|1046}}
 +
| colspan="9"| Approx {{sfrac|<var>Luck</var> + X|35}} chance<!-- computed numbers slightly incorrect -->
 
|-
 
|-
| Chance that you can kick down a door, avg(str,dex,con)=10 || rnl(35)<10 || 0.5% || 6.2% || 14.6% || 23.0% || 28.6% || 34.1% || 42.5% || 50.9% || 59.3%
+
| Chance of kicking down a door when avg(str, dex, con) is 10
 +
| <code>rnl(35)<10</code>
 +
| 0.5% || 6.2% || 14.6% || 23.0% || 28.6% || 34.1% || 42.5% || 50.9% || 59.3%
 
|-
 
|-
| Chance that you can kick down a door, avg(str,dex,con)=15 || rnl(35)<15 || 12.1% || 20.5% || 28.9% || 37.3% || 42.9% || 48.4% || 56.8% || 65.2% || 73.6%
+
| Chance of kicking down a door when avg(str, dex, con) is 15
 +
| <code>rnl(35)<15</code>
 +
| 12.1% || 20.5% || 28.9% || 37.3% || 42.9% || 48.4% || 56.8% || 65.2% || 73.6%
 
|-
 
|-
| Chance that you can kick down a door, Samurai or Monk and avg(str,con)=15, dex=15 || rnl(35)<30 || 54.9% || 63.4% || 71.8% || 80.1% || 85.7% || 91.3% || 99.7% || 99.7% || 99.7%
+
| Chance of kicking down a door as a [[Samurai]] or [[Monk]] when avg(str, con) is 15 and dex is 15
 +
| <code>rnl(35)<30</code> || 54.9% || 63.4% || 71.8% || 80.1% || 85.7% || 91.3% || 99.7% || 99.7% || 99.7%
 
|-
 
|-
| Chance that you can open a door (smoother distribution) || rnl(20)<X where X = avg( str, dex, con){{refsrc|lock.c|562}} || colspan="9"|Approx (Luck+x)/20 chance<ref>computed numbers slightly incorrect</ref>
+
| Chance of opening a door
 +
| <code>rnl(20)<X</code>, where X = avg(str, dex, con){{refsrc|lock.c|562}} || colspan="9"|Approx {{sfrac|<var>Luck</var> + X|20}} chance<ref>computed numbers slightly incorrect</ref>
 
|-
 
|-
| Chance that you can open a door, avg(str,dex,con)=10 || rnl(20)<10 || 1% || 11% || 26% || 40% || 50% || 60% || 74% || 89% || 99%
+
| Chance of opening a door when avg(str, dex, con) is 10
 +
| <code>rnl(20)<10</code>
 +
| 1% || 11% || 26% || 40% || 50% || 60% || 74% || 89% || 99%
 
|-
 
|-
| Chance that you can open a door, avg(str,dex,con)=15 || rnl(20)<15 || 21% || 36% || 51% || 65% || 75% || 85% || 99% || 99% || 99%
+
| Chance of opening a door when avg(str, dex, con) is 15
 +
| <code>rnl(20)<15</code>
 +
| 21% || 36% || 51% || 65% || 75% || 85% || 99% || 99% || 99%
 
|-
 
|-
||One criterion (the other being alignment-based) for an altar conversion{{refsrc|pray.c|1396}} (or attempt{{refsrc|pray.c|1408}}) producing a summoned minion. || rnl(your level)>6 || colspan="9"|Impossible before level 8, more likely with low luck, more likely at higher level
+
| One criterion (the other being [[alignment record|alignment]]-based) for a [[minion]] to be summoned when converting{{refsrc|pray.c|1396}} (or attempting to convert{{refsrc|pray.c|1408}}) an [[altar]]
 +
| <code>rnl(your level)>6</code>
 +
| colspan="9"|Impossible before level 8, more likely with low luck or higher level
 
|-
 
|-
||Chance of summoning a minion, all other criteria being met, at level 8 || rnl(8)>6 || 61.3% || 49.1% || 36.9% || 24.7% || 12.5% || 0.3% || 0.3% || 0.3% || 0.3%
+
| Chance of summoning a minion, all other criteria being met, at level 8
 +
| <code>rnl(8)>6</code>
 +
| 61.3% || 49.1% || 36.9% || 24.7% || 12.5% || 0.3% || 0.3% || 0.3% || 0.3%
 
|-
 
|-
||Chance of summoning a minion, all other criteria being met, at level 12 || rnl(12)>6 || 74.2% || 66.0% || 58.0% || 49.8% || 41.7% || 33.6% || 25.4% || 17.3% || 9.1%
+
| Chance of summoning a minion, all other criteria being met, at level 12
 +
| <code>rnl(12)>6</code>
 +
| 74.2% || 66.0% || 58.0% || 49.8% || 41.7% || 33.6% || 25.4% || 17.3% || 9.1%
 
|-
 
|-
||Chance of summoning a minion, all other criteria being met, at level 16 (smoother distribution) || rnl(16)>6 || 99.1% || 99.0% || 86.8% || 68.4% || 56.3% || 44.1% || 25.7% || 7.4% || 1.2%
+
| Chance of summoning a minion, all other criteria being met, at level 16
 +
| <code>rnl(16)>6</code>
 +
| 99.1% || 99.0% || 86.8% || 68.4% || 56.3% || 44.1% || 25.7% || 7.4% || 1.2%
 
|-
 
|-
||Chance of summoning a minion, all other criteria being met, at level 24 (smoother distribution) || rnl(24)>6 || 99.4% || 99.4% || 91.2% || 79.0% || 70.8% || 62.7% || 50.5% || 38.2% || 26.0%
+
| Chance of summoning a minion, all other criteria being met, at level 24
 +
| <code>rnl(24)>6</code>
 +
| 99.4% || 99.4% || 91.2% || 79.0% || 70.8% || 62.7% || 50.5% || 38.2% || 26.0%
 
|-
 
|-
|| Chance of angering your god by praying in [[Gehennom]] || rnl(alignment)>0{{refsrc|pray.c|1618}} || colspan="9"|Certain with negative alignment, impossible at alignment 1 (!), more likely with higher alignment, less likely with higher luck
+
| Chance of [[anger]]ing your god by praying in [[Gehennom]]
 +
| <code>rnl(alignment)>0</code>{{refsrc|pray.c|1618}}
 +
| colspan="9"|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 || 98.8% || 98.8% || 98.7% || 98.7% || 50% || 1.3% || 1.3% || 1.3% || 1.2%
+
| Chance of [[anger]]ing your god by praying in [[Gehennom]] at alignment 2
 +
| <code>rnl(2)>0</code>
 +
| 98.8% || 98.8% || 98.7% || 98.7% || 50% || 1.3% || 1.3% || 1.3% || 1.2%
 
|-
 
|-
|| Chance of angering your god by praying in Gehennom at alignment 4 || rnl(4)>0 || 99.4% || 99.4% || 99.3% || 99.3% || 75% || 50.7% || 26.3% || 1.9% || 1.8%
+
| Chance of [[anger]]ing your god by praying in [[Gehennom]] at alignment 4
 +
| <code>rnl(4)>0</code>
 +
| 99.4% || 99.4% || 99.3% || 99.3% || 75% || 50.7% || 26.3% || 1.9% || 1.8%
 
|-
 
|-
|| Chance of angering your god by praying in Gehennom at alignment 8 || rnl(8)>0 || 99.7% || 99.7% || 99.7% || 99.7% || 87.5% || 75.3% || 63.1% || 50.9% || 38.7%
+
| Chance of [[anger]]ing your god by praying in [[Gehennom]] at alignment 8
 +
| <code>rnl(8)>0</code>
 +
| 99.7% || 99.7% || 99.7% || 99.7% || 87.5% || 75.3% || 63.1% || 50.9% || 38.7%
 
|-
 
|-
|| Chance of angering your god by praying in Gehennom at alignment 16 (smoother distribution) || rnl(16)>0 || 99.9% || 99.9% || 99.9% || 99.9% || 93.8% || 81.6% || 63.2% || 44.9% || 26.4%
+
| Chance of [[anger]]ing your god by praying in [[Gehennom]] at alignment 16
 +
| <code>rnl(16)>0</code>
 +
| 99.9% || 99.9% || 99.9% || 99.9% || 93.8% || 81.6% || 63.2% || 44.9% || 26.4%
 
|-
 
|-
|| Chance of angering your god by praying in Gehennom at alignment 32 (smoother distribution) || rnl(32)>0 || 99.9% || 99.9% || 99.9% || 99.9% || 96.9% || 90.8% || 81.6% || 72.4% || 63.2%
+
| Chance of [[anger]]ing your god by praying in [[Gehennom]] at alignment 32
 +
| <code>rnl(32)>0</code>
 +
| 99.9% || 99.9% || 99.9% || 99.9% || 96.9% || 90.8% || 81.6% || 72.4% || 63.2%
 +
|}
 +
 
 +
=== Numerical distributions ===
 +
{| class="wikitable"
 +
!rowspan=2|Value !! rowspan=2|Code !! colspan=9|Luck
 
|-
 
|-
|colspan="11"|Numerical Distributions
+
!&minus;11 !! &minus;8 !! &minus;5 !! &minus;2 !! 0 !! +2 !! +5 !! +8 !! +11
 
|-
 
|-
| Average number of fruit that fall from a tree if you kick it || 8-rnl(7){{refsrc|dokick.c|900}} || 2.5 || 2.9 || 3.5 || 4.2 || 5 || 5.8 || 6.5 || 7.1 || 7.5
+
| Average number of fruit that fall from a [[tree]] when you kick it
 +
| <code>8-rnl(7)</code>{{refsrc|dokick.c|900}}
 +
| 2.5 || 2.9 || 3.5 || 4.2 || 5 || 5.8 || 6.5 || 7.1 || 7.5
 
|-
 
|-
| Average number of bees that are summoned from a tree if you kick it || rnl(4)+2{{refsrc|dokick.c|900}} || 5 || 5 || 4.7 || 4.2 || 3.5 || 2.8 || 2.3 || 2 || 2
+
| Average number of bees that are summoned from a tree if you kick it
 +
| <code>rnl(4)+2</code>{{refsrc|dokick.c|900}}
 +
| 5 || 5 || 4.7 || 4.2 || 3.5 || 2.8 || 2.3 || 2 || 2
 
|-
 
|-
| Amount of gold left from a [[gold golem]]'s death (average, smooth distribution) || 200-rnl(101){{refsrc|mon.c|278}} || 140 || 143 || 145 || 148 || 150 || 152 || 155 || 157 || 160
+
| Average number of [[gold piece]]s dropped by a [[gold golem]] on death
 +
| <code>200-rnl(101)</code>{{refsrc|mon.c|278}}
 +
| 140 || 143 || 145 || 148 || 150 || 152 || 155 || 157 || 160
 
|-
 
|-
|| Number of darts/arrows/etc left behind when disarming a trap (average, smooth distribution) || 50-rnl(50){{refsrc|trap.c|3274}} || 16 || 18 || 21 || 24 || 25.5 || 27 || 30 || 33 || 35
+
| Average number of darts or arrows left behind when disarming a [[dart trap]] or [[arrow trap]]
 +
| <code>50-rnl(50)</code>{{refsrc|trap.c|3274}}
 +
| 16 || 18 || 21 || 24 || 25.5 || 27 || 30 || 33 || 35
 
|}
 
|}
 
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".
 
  
 
== Mathematical analysis ==
 
== Mathematical analysis ==
  
Basically, rnl(x) generates a number between 0 and x-1, and adjusts it in proportion to the player's luck, with a small chance (which is smaller as the luck number tends toward the extremes) of leaving it alone. The net effect is that with positive or negative luck, the highest or lowest numbers on the list become vanishingly unlikely, and the odds of getting the best and worst result increase, while the odds of getting every result in between stays the same.
+
Basically, rnl(<var>x</var>) generates a number between 0 and <var>x</var>&nbsp;&minus;&nbsp;1, and adjusts it in proportion to the player's Luck, with a small chance (which is smaller when Luck tends toward the extremes) of leaving it alone. The net effect is that with positive or negative Luck, the highest or lowest numbers on the list become vanishingly unlikely, and the odds of getting the best and worst result increase, while the odds of getting every result in between stays the same.
  
Further complicating the matter is that, when x is 15 or less, the adjustment is divided by 3, which means that for those calls there is a stepwise distribution where the odds of everything are completely the same within blocks of 3 numbers (-13 to -11, -10 to -8, -7 to -5, -4 to -2, -1 to 1, 2 to 4, 5 to 7, 8 to 10, 11 to 13). Larger parameters have smoother distributions.
+
Further complicating the matter is that, when <var>x</var> is 15 or less, the adjustment is divided by 3, which means that for those calls there is a stepwise distribution where the odds of everything are almost completely the same within blocks of 3 numbers (&minus;13 to &minus;11, &minus;10 to &minus;8, &minus;7 to &minus;5, &minus;4 to &minus;2, &minus;1 to 1, 2 to 4, 5 to 7, 8 to 10, 11 to 13). Larger parameters have smoother distributions.
  
 
In addition, 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)&lt;B or rnl(A)&gt;B above.
 
In addition, 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)&lt;B or rnl(A)&gt;B above.
  
Since many of the comparisons are made against 0, having even -2 luck can cause many results to swing against the player's favor with near certainty. -1 luck is not as bad as most of these calls also have a small parameter, although it does negatively affect many things that do not call rnl (like [[prayer]] or [[wishing]]). On the flip side, positive luck's effect tends to be much less dramatic, and +2 luck still has a lot of room for improvement. +1 luck changes almost nothing significantly; the only pronounced effect it has is to cause jousting to be much safer.
+
Since many of the comparisons are made against 0, having even &minus;2 Luck can cause many results to swing against the player's favor with near certainty. &minus;1 Luck is not as bad as most of these calls also have a small parameter, although it does negatively affect many things that do not call rnl (like [[prayer]] or [[wish]]ing). On the flip side, positive Luck's effect tends to be much less dramatic, and +2 Luck still has a lot of room for improvement. +1 Luck changes almost nothing significantly; the only pronounced effect it has is to cause jousting to be much safer.
  
== Sample Distribution ==
+
== Sample distribution ==
  
This table is the computed odds of rnl(10) at each possible luck for each possible result. The 00% are around 0.24-0.26% depending on the magnitude of the luck.
+
This table is the computed odds of rnl(10) at each possible Luck for each possible result. The "0%" values are actually around 0.24–0.26% depending on the magnitude of the Luck.
  
 
{| class="wikitable"
 
{| class="wikitable"
 
!Luck
 
!Luck
!colspan="10"|Simplified Results
+
!colspan="10"|Simplified results
 
|-
 
|-
 
| ||0||1||2||3||4||5||6||7||8||9
 
| ||0||1||2||3||4||5||6||7||8||9
 
|-
 
|-
| -13||00%||00%||00%||00%||10%||10%||10%||10%||10%||49%
+
| −13|| 0%|| 0%|| 0%|| 0%||10%||10%||10%||10%||10%||49%
 
|-
 
|-
| -12||00%||00%||00%||00%||10%||10%||10%||10%||10%||49%
+
| −12|| 0%|| 0%|| 0%|| 0%||10%||10%||10%||10%||10%||49%
 
|-
 
|-
| -11||00%||00%||00%||00%||10%||10%||10%||10%||10%||49%
+
| −11|| 0%|| 0%|| 0%|| 0%||10%||10%||10%||10%||10%||49%
 
|-
 
|-
| -10||00%||00%||00%||10%||10%||10%||10%||10%||10%||39%
+
| −10|| 0%|| 0%|| 0%||10%||10%||10%||10%||10%||10%||39%
 
|-
 
|-
-9||00%||00%||00%||10%||10%||10%||10%||10%||10%||39%
+
−9|| 0%|| 0%|| 0%||10%||10%||10%||10%||10%||10%||39%
 
|-
 
|-
-8||00%||00%||00%||10%||10%||10%||10%||10%||10%||39%
+
−8|| 0%|| 0%|| 0%||10%||10%||10%||10%||10%||10%||39%
 
|-
 
|-
-7||00%||00%||10%||10%||10%||10%||10%||10%||10%||29%
+
−7|| 0%|| 0%||10%||10%||10%||10%||10%||10%||10%||29%
 
|-
 
|-
-6||00%||00%||10%||10%||10%||10%||10%||10%||10%||29%
+
−6|| 0%|| 0%||10%||10%||10%||10%||10%||10%||10%||29%
 
|-
 
|-
-5||00%||00%||10%||10%||10%||10%||10%||10%||10%||29%
+
−5|| 0%|| 0%||10%||10%||10%||10%||10%||10%||10%||29%
 
|-
 
|-
-4||00%||10%||10%||10%||10%||10%||10%||10%||10%||20%
+
−4|| 0%||10%||10%||10%||10%||10%||10%||10%||10%||20%
 
|-
 
|-
-3||00%||10%||10%||10%||10%||10%||10%||10%||10%||20%
+
−3|| 0%||10%||10%||10%||10%||10%||10%||10%||10%||20%
 
|-
 
|-
-2||00%||10%||10%||10%||10%||10%||10%||10%||10%||20%
+
−2|| 0%||10%||10%||10%||10%||10%||10%||10%||10%||20%
 
|-
 
|-
-1||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%
 
|  0||10%||10%||10%||10%||10%||10%||10%||10%||10%||10%
Line 190: Line 268:
 
|  1||10%||10%||10%||10%||10%||10%||10%||10%||10%||10%
 
|  1||10%||10%||10%||10%||10%||10%||10%||10%||10%||10%
 
|-
 
|-
|  2||20%||10%||10%||10%||10%||10%||10%||10%||10%||00%
+
|  2||20%||10%||10%||10%||10%||10%||10%||10%||10%|| 0%
 
|-
 
|-
|  3||20%||10%||10%||10%||10%||10%||10%||10%||10%||00%
+
|  3||20%||10%||10%||10%||10%||10%||10%||10%||10%|| 0%
 
|-
 
|-
|  4||20%||10%||10%||10%||10%||10%||10%||10%||10%||00%
+
|  4||20%||10%||10%||10%||10%||10%||10%||10%|| 0%|| 0%
 
|-
 
|-
|  5||29%||10%||10%||10%||10%||10%||10%||10%||00%||00%
+
|  5||29%||10%||10%||10%||10%||10%||10%||10%|| 0%|| 0%
 
|-
 
|-
|  6||29%||10%||10%||10%||10%||10%||10%||10%||00%||00%
+
|  6||29%||10%||10%||10%||10%||10%||10%||10%|| 0%|| 0%
 
|-
 
|-
|  7||29%||10%||10%||10%||10%||10%||10%||10%||00%||00%
+
|  7||29%||10%||10%||10%||10%||10%||10%||10%|| 0%|| 0%
 
|-
 
|-
|  8||39%||10%||10%||10%||10%||10%||10%||00%||00%||00%
+
|  8||39%||10%||10%||10%||10%||10%||10%|| 0%|| 0%|| 0%
 
|-
 
|-
|  9||39%||10%||10%||10%||10%||10%||10%||00%||00%||00%
+
|  9||39%||10%||10%||10%||10%||10%||10%|| 0%|| 0%|| 0%
 
|-
 
|-
|  10||39%||10%||10%||10%||10%||10%||10%||00%||00%||00%
+
|  10||39%||10%||10%||10%||10%||10%||10%|| 0%|| 0%|| 0%
 
|-
 
|-
|  11||49%||10%||10%||10%||10%||10%||00%||00%||00%||00%
+
|  11||49%||10%||10%||10%||10%||10%|| 0%|| 0%|| 0%|| 0%
 
|-
 
|-
|  12||49%||10%||10%||10%||10%||10%||00%||00%||00%||00%
+
|  12||49%||10%||10%||10%||10%||10%|| 0%|| 0%|| 0%|| 0%
 
|-
 
|-
|  13||49%||10%||10%||10%||10%||10%||00%||00%||00%||00%
+
|  13||49%||10%||10%||10%||10%||10%|| 0%|| 0%|| 0%|| 0%
 
|}
 
|}
 +
 +
== History ==
 +
 +
In [[NetHack 3.4.3]], the formulas were slightly different.<ref>[https://nethackwiki.com/wiki/Source:NetHack_3.4.3/src/rnd.c#rnl rnl in rnd.c for Nethack 3.4.3]</ref>
 +
 +
Let <var>R</var> be a random integer number from 0 to <var>x</var>&nbsp;&minus;&nbsp;1 (inclusive).
 +
 +
If Luck&nbsp;=&nbsp;0, <var>R</var> is returned.
 +
 +
Otherwise, with {{sfrac|1|50 &minus; Luck}} chance (since Luck ranges from &minus;13 to 13, the chance should be between {{sfrac|37}} and {{sfrac|63}}), <var>R</var> is returned.
 +
 +
Otherwise, if <var>x</var>&nbsp;&le;&nbsp; 15 and Luck&nbsp;&ge;&nbsp;&minus;5 (that is, <var>x</var> is not too big and the player is not too unlucky), {{sfrac|Luck|3}} (truncated towards zero) is subtracted from <var>R</var>, then <var>R</var> is forced into the interval [0, <var>x</var>&nbsp;&minus;&nbsp;1] and returned.
 +
 +
Otherwise, Luck is subtracted from <var>R</var>, then <var>R</var> is forced into the interval [0, <var>x</var>&nbsp;&minus;&nbsp;1] and returned.
  
 
== References ==
 
== References ==

Latest revision as of 00:57, 2 April 2022

Not to be confused with rn1.

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.

Formula

See source code in [1]

For rnl(x), let L equal your Luck, including the luck item bonus or penalty, whether positive, negative, or zero.

If x ≤ 15, L = L3, rounded toward the nearest integer.

If L = 0, return rn2(x).

With chance 137 + |L|, return rn2(x).

Otherwise, return rn2(x) - L, but no less than 0 and no more than x - 1.

This means that rnl(x) is almost always equivalent to rn2(x) - Luck when x > 15. The chance of Luck being ignored is less than 3% in any case, and even smaller for stronger (positive or negative) Luck. For smaller values of x, rn2(x) - Luck3 is the most likely approximation.

How it's used

In the tables below, 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".

Events based solely on Luck

Situation Code Luck
−11 −8 −5 −2 0 +2 +5 +8 +11
Chance of your god helping you if you pray with exactly 0 alignment rnl(2)==0[2] 1% 1% 1% 1% 50% 99% 99% 99% 99%
Chance of writing a scroll you have not seen rnl(15)==0[3] 0.2% 0.2% 0.2% 0.2% 6.7% 13.2% 19.7% 26.2% 32.7%
Chance of writing a scroll you have not seen, as a Wizard rnl(5)==0[4] 0.5% 0.5% 0.5% 0.5% 20.0% 39.5% 59.0% 78.5% 98.0%
Chance of failing to set a land mine (in which case it blows up) or beartrap (nothing happens) while riding and unskilled at riding rnl(10)>5[5] 79% 69% 59% 50% 40% 30% 21% 11% 1%
Chance of failing to set a land mine (in which case it blows up) or beartrap (nothing happens) while riding and unskilled at riding, and fumbling or using a cursed trap rnl(10)>3[6] 99% 89% 79% 70% 60% 50% 41% 31% 21%
Chance that a trap goes off after you set it, if it was cursed or you were fumbling rnl(10)>5[7] 79% 69% 59% 50% 40% 30% 21% 11% 1%
Chance of snagging an item you can pick up when using a bullwhip (instead of having it slip free) rnl(6)==0[8] 0.4% 0.4% 0.4% 0.4% 16.7% 32.9% 49.1% 65.4% 81.8%
Chance of finding secret passages and doors on each surrounding square when searching rnl(7)==0[9] 0.3% 0.4% 0.4% 0.4% 14.3% 28.2% 42.1% 56.1% 70.0%
Chance of finding secret passages and doors on each surrounding square when searching, while wearing a pair of lenses rnl(5)==0[10] 0.5% 0.5% 0.5% 0.5% 20.0% 39.5% 59.0% 78.5% 98.0%
Chance of finding secret passages 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.2% 1.3% 1.3% 1.3% 50% 98.7% 98.7% 98.8% 98.8%
Chance of finding a hidden trap when searching rnl(8)==0[12] 0.3% 0.3% 0.3% 0.3% 12.5% 24.7% 36.9% 49.1% 61.3%
Chance of a blessed projectile not breaking when thrown rnl(4)==0[13] 0.6% 0.6% 0.6% 0.7% 25% 49.3% 73.7% 98.1% 98.2%
Chance of being petrified if your saddle slips off[14] or is destroyed, or you are polymorphed and lose stone resistance,[15] when you are riding a steed that petrifies on touch (likely due to your horse having just polymorphed into a cockatrice) rnl(3)>0 99.2% 99.2% 99.1% 99.1% 66.7% 34.2% 1.7% 1.7% 1.6%
Chance of a random levelport when attempting to controlled levelport (or cancel) while confused rnl(5)>0[16] 99.5% 99.5% 99.5% 99.5% 80.0% 60.5% 41.0% 21.5% 2.0%
Chance of blessed equipment not being eroded by rust[17] or water[18] damage, or blessed flammable items not being burned by fire damage[19] rnl(4)==0 0.6% 0.6% 0.6% 0.7% 25% 49.3% 73.7% 98.1% 98.2%
Chance of a monster becoming angry when it steps in a trap set by you,[20] or of you triggering a trap when failing to disarm it[21] rnl(5)>0 99.5% 99.5% 99.5% 99.5% 80.0% 60.5% 41.0% 21.5% 2.0%
Chance of a hostile, awake, unfrozen, mindful, non-​@ monster becoming peaceful when you free it from a trap not set by you rnl(10)<8[22] 40.1% 50.8% 60.5% 70.3% 80.0% 89.7% 99.5% 99.5% 99.5%
Chance of a lawful player getting +1 alignment for the above rnl(8)==0, one-third of the time[23] 0.1% 0.1% 0.1% 0.1% 4.2% 8.2% 12.3% 16.4% 20.4%
Chance of getting +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.7% 0.8% 10.5% 20.2% 30% 39.7% 49.5% 59.3% 69.0%
Chance of having a boomerang break when used as a melee weapon rnl(4)==3[25] 98.2% 98.1% 73.7% 49.3% 25% 0.7% 0.6% 0.6% 0.6%
Chance of having a non-artifact lance break when successfully jousting a solid monster rnl(50)==49, 15 of the time[26] 4.71% 3.53% 2.35% 1.18% 0.4% 0.01% 0.01% 0.01% 0.01%

Events based on Luck and other stats

Situation Code Luck
−11 −8 −5 −2 0 +2 +5 +8 +11
Chance of kicking down a door rnl(35)<X, where X = avg(str, dex, con) + (dex if Samurai or Monk)[27] Approx Luck + X35 chance
Chance of kicking down a door when avg(str, dex, con) is 10 rnl(35)<10 0.5% 6.2% 14.6% 23.0% 28.6% 34.1% 42.5% 50.9% 59.3%
Chance of kicking down a door when avg(str, dex, con) is 15 rnl(35)<15 12.1% 20.5% 28.9% 37.3% 42.9% 48.4% 56.8% 65.2% 73.6%
Chance of kicking down a door as a Samurai or Monk when avg(str, con) is 15 and dex is 15 rnl(35)<30 54.9% 63.4% 71.8% 80.1% 85.7% 91.3% 99.7% 99.7% 99.7%
Chance of opening a door rnl(20)<X, where X = avg(str, dex, con)[28] Approx Luck + X20 chance[29]
Chance of opening a door when avg(str, dex, con) is 10 rnl(20)<10 1% 11% 26% 40% 50% 60% 74% 89% 99%
Chance of opening a door when avg(str, dex, con) is 15 rnl(20)<15 21% 36% 51% 65% 75% 85% 99% 99% 99%
One criterion (the other being alignment-based) for a minion to be summoned when converting[30] (or attempting to convert[31]) an altar rnl(your level)>6 Impossible before level 8, more likely with low luck or higher level
Chance of summoning a minion, all other criteria being met, at level 8 rnl(8)>6 61.3% 49.1% 36.9% 24.7% 12.5% 0.3% 0.3% 0.3% 0.3%
Chance of summoning a minion, all other criteria being met, at level 12 rnl(12)>6 74.2% 66.0% 58.0% 49.8% 41.7% 33.6% 25.4% 17.3% 9.1%
Chance of summoning a minion, all other criteria being met, at level 16 rnl(16)>6 99.1% 99.0% 86.8% 68.4% 56.3% 44.1% 25.7% 7.4% 1.2%
Chance of summoning a minion, all other criteria being met, at level 24 rnl(24)>6 99.4% 99.4% 91.2% 79.0% 70.8% 62.7% 50.5% 38.2% 26.0%
Chance of angering your god by praying in Gehennom rnl(alignment)>0[32] 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 98.8% 98.8% 98.7% 98.7% 50% 1.3% 1.3% 1.3% 1.2%
Chance of angering your god by praying in Gehennom at alignment 4 rnl(4)>0 99.4% 99.4% 99.3% 99.3% 75% 50.7% 26.3% 1.9% 1.8%
Chance of angering your god by praying in Gehennom at alignment 8 rnl(8)>0 99.7% 99.7% 99.7% 99.7% 87.5% 75.3% 63.1% 50.9% 38.7%
Chance of angering your god by praying in Gehennom at alignment 16 rnl(16)>0 99.9% 99.9% 99.9% 99.9% 93.8% 81.6% 63.2% 44.9% 26.4%
Chance of angering your god by praying in Gehennom at alignment 32 rnl(32)>0 99.9% 99.9% 99.9% 99.9% 96.9% 90.8% 81.6% 72.4% 63.2%

Numerical distributions

Value Code Luck
−11 −8 −5 −2 0 +2 +5 +8 +11
Average number of fruit that fall from a tree when you kick it 8-rnl(7)[33] 2.5 2.9 3.5 4.2 5 5.8 6.5 7.1 7.5
Average number of bees that are summoned from a tree if you kick it rnl(4)+2[34] 5 5 4.7 4.2 3.5 2.8 2.3 2 2
Average number of gold pieces dropped by a gold golem on death 200-rnl(101)[35] 140 143 145 148 150 152 155 157 160
Average number of darts or arrows left behind when disarming a dart trap or arrow trap 50-rnl(50)[36] 16 18 21 24 25.5 27 30 33 35

Mathematical analysis

Basically, rnl(x) generates a number between 0 and x − 1, and adjusts it in proportion to the player's Luck, with a small chance (which is smaller when Luck tends toward the extremes) of leaving it alone. The net effect is that with positive or negative Luck, the highest or lowest numbers on the list become vanishingly unlikely, and the odds of getting the best and worst result increase, while the odds of getting every result in between stays the same.

Further complicating the matter is that, when x is 15 or less, the adjustment is divided by 3, which means that for those calls there is a stepwise distribution where the odds of everything are almost completely the same within blocks of 3 numbers (−13 to −11, −10 to −8, −7 to −5, −4 to −2, −1 to 1, 2 to 4, 5 to 7, 8 to 10, 11 to 13). Larger parameters have smoother distributions.

In addition, 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.

Since many of the comparisons are made against 0, having even −2 Luck can cause many results to swing against the player's favor with near certainty. −1 Luck is not as bad as most of these calls also have a small parameter, although it does negatively affect many things that do not call rnl (like prayer or wishing). On the flip side, positive Luck's effect tends to be much less dramatic, and +2 Luck still has a lot of room for improvement. +1 Luck changes almost nothing significantly; the only pronounced effect it has is to cause jousting to be much safer.

Sample distribution

This table is the computed odds of rnl(10) at each possible Luck for each possible result. The "0%" values are actually around 0.24–0.26% depending on the magnitude of the Luck.

Luck Simplified results
0 1 2 3 4 5 6 7 8 9
−13 0% 0% 0% 0% 10% 10% 10% 10% 10% 49%
−12 0% 0% 0% 0% 10% 10% 10% 10% 10% 49%
−11 0% 0% 0% 0% 10% 10% 10% 10% 10% 49%
−10 0% 0% 0% 10% 10% 10% 10% 10% 10% 39%
−9 0% 0% 0% 10% 10% 10% 10% 10% 10% 39%
−8 0% 0% 0% 10% 10% 10% 10% 10% 10% 39%
−7 0% 0% 10% 10% 10% 10% 10% 10% 10% 29%
−6 0% 0% 10% 10% 10% 10% 10% 10% 10% 29%
−5 0% 0% 10% 10% 10% 10% 10% 10% 10% 29%
−4 0% 10% 10% 10% 10% 10% 10% 10% 10% 20%
−3 0% 10% 10% 10% 10% 10% 10% 10% 10% 20%
−2 0% 10% 10% 10% 10% 10% 10% 10% 10% 20%
−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 20% 10% 10% 10% 10% 10% 10% 10% 10% 0%
3 20% 10% 10% 10% 10% 10% 10% 10% 10% 0%
4 20% 10% 10% 10% 10% 10% 10% 10% 0% 0%
5 29% 10% 10% 10% 10% 10% 10% 10% 0% 0%
6 29% 10% 10% 10% 10% 10% 10% 10% 0% 0%
7 29% 10% 10% 10% 10% 10% 10% 10% 0% 0%
8 39% 10% 10% 10% 10% 10% 10% 0% 0% 0%
9 39% 10% 10% 10% 10% 10% 10% 0% 0% 0%
10 39% 10% 10% 10% 10% 10% 10% 0% 0% 0%
11 49% 10% 10% 10% 10% 10% 0% 0% 0% 0%
12 49% 10% 10% 10% 10% 10% 0% 0% 0% 0%
13 49% 10% 10% 10% 10% 10% 0% 0% 0% 0%

History

In NetHack 3.4.3, the formulas were slightly different.[37]

Let R be a random integer number from 0 to x − 1 (inclusive).

If Luck = 0, R is returned.

Otherwise, with 150 − Luck chance (since Luck ranges from −13 to 13, the chance should be between 137 and 163), R is returned.

Otherwise, if x ≤  15 and Luck ≥ −5 (that is, x is not too big and the player is not too unlucky), Luck3 (truncated towards zero) is subtracted from R, then R is forced into the interval [0, x − 1] and returned.

Otherwise, Luck is subtracted from R, then R is forced into the interval [0, x − 1] and returned.

References