Difference between revisions of "Rnl"

From NetHackWiki
Jump to navigation Jump to search
(How it's used: source was misread here)
Line 2: Line 2:
 
'''rnl(x)'''<ref>{{function|rnd.c|rnl}}</ref> is a pseudo-random number function used in NetHack when a result should be weighted by [[Luck]].
 
'''rnl(x)'''<ref>{{function|rnd.c|rnl}}</ref> 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.  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).
+
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.
  
 
== How it's used ==
 
== How it's used ==
Line 9: Line 9:
  
 
{| class="wikitable"
 
{| class="wikitable"
!Situation!!Code!!colspan="7"|Luck
+
!Situation!!Code!!colspan="9"|Luck
 
|-
 
|-
| || ||-13||-5||-2||+3||+6||+9||+12
+
| || ||-11||-8||-5||-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% || 50% || 99% || 99% || 99% || 99%
+
| 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 writing a scroll you have not seen || rnl(15)==0{{refsrc|write.c|201}} || .1% || .1% || 6.7% || 13% || 20% || 26% || 33%
+
| 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 writing a scroll you have not seen, as a Wizard || rnl(3)==0{{refsrc|write.c|201}} || .5% || .6% || 33.3% || 66.0% || 98.5% || 98.4% || 98.2%
+
| 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 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{{refsrc|apply.c|2034}} || 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 || rnl(10)>5{{refsrc|apply.c|2034}} || 79% || 69% || 59% || 50% || 40% || 30% || 21% || 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{{refsrc|apply.c|2034}} || 99% || 70% || 60% || 50% || 40% || 31% || 21%
+
| 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{{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}} || 99% || 50% || 40% || 30% || 20% || 11% || 1%
+
| 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 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.3% || 0.3% || 16.7% || 33.0% || 49.2% || 65.4% || 81.6%
+
| 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 finding secret corridors and doors on each surrounding square when searching || rnl(7)==0{{refsrc|detect.c|1191}} || 0% || 0% || 14% || 28% || 42% || 56% || 70%
+
| 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 corridors and doors on each surrounding square when searching, while wearing [[lenses]] || rnl(5)==0{{refsrc|detect.c|1183}} || 0% || 0% || 20% || 40% || 59% || 79% || 98%
+
| 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 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% || 1% || 50% || 99% || 99% || 99% || 99%
+
| 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 a hidden trap when searching || rnl(8)==0{{refsrc|detect.c|1248}} || 0% || 0% || 12% || 25% || 37% || 49% || 61%
+
| 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 that a blessed projectile is not broken when thrown || rnl(4)==0{{refsrc|dothrow.c|1332}} || .4% || .5% || 25.0% || 49.5% || 73.9% || 98.2% || 98.0%
+
| 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 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.5% || 99.4% || 66.7% || 34.0% || 1.5% || 1.6% || 1.8%
+
| 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 a random levelport when attempting to controlled levelport (or cancel) while confused || rnl(5)>0{{refsrc|teleport.c|606}} || 99.7% || 99.6% || 80.0% || 60.4% || 40.9% || 21.5% || 2.1%
+
| 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 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 || .4% || .5% || 25.0% || 49.5% || 73.9% || 98.2% || 98.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 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.7% || 99.6% || 80.0% || 60.4% || 40.9% || 21.5% || 2.1%
+
| 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 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{{refsrc|trap.c|3166}} || 1% || 70% || 80% || 90% || 100% || 100% || 99%
+
| 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 that a lawful player gets +1 alignment for the above || rnl(8)==0 times 1/3{{refsrc|trap.c|3176}} || 0% || 0% || 4% || 8% || 12% || 16% || 20%
+
| 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 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% || 20% || 30% || 40% || 50% || 59% || 69%
+
| 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 that a boomerang will break when used as a melee weapon || rnl(4)==3{{refsrc|uhitm.c|587}} || 99% || 50% || 25% || 1% || 1% || 1% || 1%
+
| 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 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{{refsrc|uhitm.c|1153}} || 27.59% || 11.82% || 5.92% || .04% || .05% || .05% || .05%
+
| Chance that a successful joust, against a solid monster, breaks your non-artifact lance (very smooth distribution, 27% at Luck -13, .05% at Luck 1) || rnl(50)==49{{refsrc|uhitm.c|1153}} || 23.54% || 17.64% || 11.76% || 5.90% || 2% || 0.05% || 0.05% || 0.04% || 0.04%
 
|-
 
|-
|colspan="9"|Probability based on non-Luck stats
+
|colspan="11"|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]]){{refsrc|dokick.c|1046}} || colspan="7"| Approx ((Luck+X)*2.9)+.1% for negative luck, 99.9-((35-(Luck+X))*2.9)% for positive luck<ref>computed numbers slightly incorrect</ref>
+
| 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 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)=10 || rnl(35)<10 || 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 || 6% || 29% || 37% || 51% || 60% || 68% || 76%
+
| 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 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 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 that you can open a door (smoother distribution) || rnl(20)<X where X = avg( str, dex, con){{refsrc|lock.c|562}} || colspan="7"|Approx ((Luck+X)*5)+.1% for negative luck, 99.9-((20-(Luck+X))*5)% for positive luck<ref>computed numbers slightly incorrect</ref>
+
| 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 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)=10 || rnl(20)<10 || 1% || 11% || 26% || 40% || 50% || 60% || 74% || 89% || 99%
 
|-
 
|-
| Chance that you can open a door, avg(str,dex,con)=15 || rnl(20)<15 || 11% || 50% || 65% || 90% || 99% || 99% || 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%
 
|-
 
|-
||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="7"|Impossible before level 8, more likely with low luck, more likely at higher level
+
||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
 
|-
 
|-
||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 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 (smoother distribution) || rnl(12)>6 || 99% || 50% || 42% || 34% || 25% || 17% || 9%
+
||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 (smoother distribution) || rnl(16)>6 || 99% || 87% || 69% || 38% || 20% || 1% || 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 24 (smoother distribution) || rnl(24)>6 || 100% || 91% || 79% || 59% || 46% || 34% || 22%
+
||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 angering your god by praying in [[Gehennom]] || rnl(alignment)>0{{refsrc|pray.c|1618}} || colspan="7"|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]] || 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 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 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 || 100% || 100% || 75% || 51% || 26% || 2% || 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 || 100% || 100% || 88% || 75% || 63% || 51% || 39%
+
|| 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 (smoother distribution) || rnl(16)>0 || 100% || 100% || 100% || 75% || 57% || 39% || 21%
+
|| 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 angering your god by praying in Gehennom at alignment 32 (smoother distribution) || rnl(32)>0 || 100% || 100% || 100% || 88% || 79% || 69% || 60%
+
|| 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%
 
|-
 
|-
|colspan="9"|Numerical Distributions
+
|colspan="11"|Numerical Distributions
 
|-
 
|-
| Average number of fruit that fall from a tree if you kick it and are otherwise lucky || 8-rnl(7){{refsrc|dokick.c|900}} || 2 || 4.2 || 5.0 || 5.8 || 6.5 || 7.1 || 7.5
+
| 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 bees that fall from a tree if you kick it and are otherwise unlucky || rnl(4)+2{{refsrc|dokick.c|900}} || 5.0 || 4.2 || 3.5 || 2.8 || 2.3 || 2.0 || 2.0
+
| 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
 
|-
 
|-
| Amount of gold left from a [[gold golem]]'s death (average, smooth distribution) || 200-rnl(101){{refsrc|mon.c|278}} || 138 || 145 || 148 || 153 || 156 || 158 || 161
+
| 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
 
|-
 
|-
|| Number of darts/arrows/etc left behind when disarming a trap (average, smooth distribution) || 50-rnl(50){{refsrc|trap.c|3274}} || 14 || 21 || 24 || 28 || 31 || 33 || 36
+
|| 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
 
|}
 
|}
  
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.
+
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 ==
  
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.
+
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.
  
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.
+
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 smae 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.
  
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.
+
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.
 
 
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)&lt;B or rnl(A)&gt;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.
 
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.
Line 122: Line 118:
 
== Sample Distribution ==
 
== 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%.
+
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.
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 130: Line 126:
 
| ||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%||00%||00%||00%||00%||00%||98%
+
| -13||00%||00%||00%||00%||10%||10%||10%||10%||10%||49%
 
|-
 
|-
| -12||00%||00%||00%||00%||00%||00%||00%||00%||00%||98%
+
| -12||00%||00%||00%||00%||10%||10%||10%||10%||10%||49%
 
|-
 
|-
| -11||00%||00%||00%||00%||00%||00%||00%||00%||00%||98%
+
| -11||00%||00%||00%||00%||10%||10%||10%||10%||10%||49%
 
|-
 
|-
| -10||00%||00%||00%||00%||00%||00%||00%||00%||00%||98%
+
| -10||00%||00%||00%||10%||10%||10%||10%||10%||10%||39%
 
|-
 
|-
|  -9||00%||00%||00%||00%||00%||00%||00%||00%||00%||98%
+
|  -9||00%||00%||00%||10%||10%||10%||10%||10%||10%||39%
 
|-
 
|-
|  -8||00%||00%||00%||00%||00%||00%||00%||00%||10%||88%
+
|  -8||00%||00%||00%||10%||10%||10%||10%||10%||10%||39%
 
|-
 
|-
|  -7||00%||00%||00%||00%||00%||00%||00%||10%||10%||78%
+
|  -7||00%||00%||10%||10%||10%||10%||10%||10%||10%||29%
 
|-
 
|-
|  -6||00%||00%||00%||00%||00%||00%||10%||10%||10%||68%
+
|  -6||00%||00%||10%||10%||10%||10%||10%||10%||10%||29%
 
|-
 
|-
|  -5||00%||10%||10%||10%||10%||10%||10%||10%||10%||19%
+
|  -5||00%||00%||10%||10%||10%||10%||10%||10%||10%||29%
 
|-
 
|-
|  -4||00%||10%||10%||10%||10%||10%||10%||10%||10%||19%
+
|  -4||00%||10%||10%||10%||10%||10%||10%||10%||10%||20%
 
|-
 
|-
|  -3||00%||10%||10%||10%||10%||10%||10%||10%||10%||19%
+
|  -3||00%||10%||10%||10%||10%||10%||10%||10%||10%||20%
 
|-
 
|-
|  -2||10%||10%||10%||10%||10%||10%||10%||10%||10%||10%
+
|  -2||00%||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%
Line 160: Line 156:
 
|  1||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%
+
|  2||20%||10%||10%||10%||10%||10%||10%||10%||10%||00%
 
|-
 
|-
|  3||19%||10%||10%||10%||10%||10%||10%||10%||10%||00%
+
|  3||20%||10%||10%||10%||10%||10%||10%||10%||10%||00%
 
|-
 
|-
|  4||19%||10%||10%||10%||10%||10%||10%||10%||10%||00%
+
|  4||20%||10%||10%||10%||10%||10%||10%||10%||10%||00%
 
|-
 
|-
|  5||19%||10%||10%||10%||10%||10%||10%||10%||10%||00%
+
|  5||29%||10%||10%||10%||10%||10%||10%||10%||00%||00%
 
|-
 
|-
 
|  6||29%||10%||10%||10%||10%||10%||10%||10%||00%||00%
 
|  6||29%||10%||10%||10%||10%||10%||10%||10%||00%||00%
Line 172: Line 168:
 
|  7||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%
+
|  8||39%||10%||10%||10%||10%||10%||10%||00%||00%||00%
 
|-
 
|-
 
|  9||39%||10%||10%||10%||10%||10%||10%||00%||00%||00%
 
|  9||39%||10%||10%||10%||10%||10%||10%||00%||00%||00%
Line 178: Line 174:
 
|  10||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%
+
|  11||49%||10%||10%||10%||10%||10%||00%||00%||00%||00%
 
|-
 
|-
 
|  12||49%||10%||10%||10%||10%||10%||00%||00%||00%||00%
 
|  12||49%||10%||10%||10%||10%||10%||00%||00%||00%||00%
Line 189: Line 185:
 
<references />
 
<references />
  
{{nethack-343}}
 
 
[[Category:Random number functions]]
 
[[Category:Random number functions]]

Revision as of 07:25, 29 February 2016

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.

How it's used

rnl is used for the following purposes:

Situation Code Luck
-11 -8 -5 -2 0 +2 +5 +8 +11
Whether your god will help if you pray with exactly 0 alignment rnl(2)==0[2] 01% 01% 01% 01% 50% 99% 99% 99% 99%
Chance of writing a scroll you have not seen rnl(15)==0[3] .2% .2% .2% .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[4] .8% .8% .9% .9% 33.3% 65.8% 98.3% 98.3% 98.3%
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] 79% 69% 59% 50% 40% 30% 21% 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% 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[7] 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[8] 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[9] 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[10] 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[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 that a blessed projectile is not broken when thrown rnl(4)==0[13] 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[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.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 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 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[20], or that you trigger 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 that a hostile, awake, unfrozen, mindful, nonhuman monster becomes 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 that a lawful player gets +1 alignment for the above rnl(8)==0 times 1/3[23] 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[24] 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[25] 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, 27% at Luck -13, .05% at Luck 1) rnl(50)==49[26] 23.54% 17.64% 11.76% 5.90% 2% 0.05% 0.05% 0.04% 0.04%
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)/35 chance[28]
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 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 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 that you can open a door (smoother distribution) rnl(20)<X where X = avg( str, dex, con)[29] Approx (Luck+x)/20 chance[30]
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 that you can open a door, avg(str,dex,con)=15 rnl(20)<15 21% 36% 51% 65% 75% 85% 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 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 (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 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 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 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 (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 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%
Numerical Distributions
Average number of fruit that fall from a tree if you kick it 8-rnl(7)[34] 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[35] 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)[36] 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)[37] 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

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.

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 smae 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.

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 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.

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

References