Difference between revisions of "Rnl"

From NetHackWiki
Jump to navigation Jump to search
(Massive rewrite)
(How it's used)
Line 8: Line 8:
 
rnl is used for the following purposes:
 
rnl is used for the following purposes:
  
* rnl(2)>0 is whether your god will help if you pray with low positive alignment<ref>{{sourcecode|pray.c|828}}</ref>.  ~1% at Luck<-2, 50% at -2<=Luck<=2, 99% at Luck>2.
+
* rnl(2)==0 is whether your god will help if you pray with low positive alignment<ref>{{sourcecode|pray.c|828}}</ref>.  ~1% at Luck<-2, 50% at -2<=Luck<=2, 99% at Luck>2.
  
 
* rnl(your level)>6  is one criterion for an altar conversion<ref>{{sourcecode|pray.c|1396}}</ref> (or attempt<ref>{{sourcecode|pray.c|1408}}</ref>) producing a summoned minion.  This is impossible before level 8, very likely with very low luck, almost impossible with high luck, more likely at higher level.
 
* rnl(your level)>6  is one criterion for an altar conversion<ref>{{sourcecode|pray.c|1396}}</ref> (or attempt<ref>{{sourcecode|pray.c|1408}}</ref>) producing a summoned minion.  This is impossible before level 8, very likely with very low luck, almost impossible with high luck, more likely at higher level.

Revision as of 10:01, 20 August 2009

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 sometmes skewed very slighly in reverse (see rnl(3)>0 below).

How it's used

rnl is used for the following purposes:

  • rnl(2)==0 is whether your god will help if you pray with low positive alignment[2]. ~1% at Luck<-2, 50% at -2<=Luck<=2, 99% at Luck>2.
  • rnl(your level)>6 is one criterion for an altar conversion[3] (or attempt[4]) producing a summoned minion. This is impossible before level 8, very likely with very low luck, almost impossible with high luck, more likely at higher level.
  • rnl(your alignment)>0 is one criterion for angering your god by praying in Gehennom[5]. This is impossible at alignment 1, likely to almost certain with low luck, likely to almost certain with high alignment.
  • rnl(15)==0 (or rnl(3) for a Wizard) is the chance of writing a scroll you have not seen[6]. .1% at Luck<-2, 6.66% at -2<=Luck<=2, 13.33% at Luck 3-5, 20% at 6-8, 26% at 9-11, 32% at 12+. For Wizards, .6% at Luck<=-2, 33% at -2<=Luck<=2, 66% at Luck 3-5, 98% at Luck 6+.
  • rnl(10)>5 (or >3 if Fumbling or cursed) is the chance to fail to set a landmine (then it blows up) or bear trap (nothing happens) from a horse when riding while unskilled[7]. 99% at Luck<=-6, 49% at -5<=Luck<=-3, 40% at -2<=Luck<=2, 30% at Luck 3-5, 20% at 6-8, 10% at 9-11, 1% at 12+. Fumbling or cursed is 20% worse.
  • rnl(10)>5 is also the chance that a trap goes off after you set it, if it was cursed or you fumbled[8].
  • rnl(6)==0 is the chance that an otherwise pickup-able object slips free when you use a whip to pick it up[9]. 99% at Luck<-2, 17% at -2<=Luck<=2, 33% at Luck 3-5, 49% at Luck 6-8, 66% at Luck 9-11, 82% at Luck 12+.
  • rnl(7)==0 is the chance of finding secret cooridors and doors on each surrounding square when searching[10] (or better with lenses or an artifact that grants searching[11]). Slightly worse to much better odds than the opposite of rnl(6)==0 above, better to much better than rnl(8)==0 below.
  • rnl(8)==0 is the chance of finding a hidden trap when searching[12]. 1% at Luck<-2, 13% at -2<=Luck<=2, 25% at Luck 3-5, 37% at Luck 6-8, 49% at Luck 9-11, 61% at Luck 12+
  • 8-rnl(7) [13] is the number of fruit that fall from a tree if you kick it and are otherwise lucky. Mostly 1 fruit at Luck<-5, a relatively even distribution from 1-8 at -5<=Luck<=5, improving up to 61% chance of 8 fruit at Luck 12+.
  • rnl(4)+2 is the number of bees that fall from a tree if you kick it and are otherwise unlucky[14]. Mostly 5 bees at Luck<-5, a relatively even distribution from 2-5 at -5<=Luck<=5, improving up to 98% chance of 2 bees at Luck 9+.
  • rnl(4)==0 is the chance that a blessed projectile is not broken[15]. .5% for Luck<-2, 25% for -2<=Luck<=2, 49% for Luck 3-5, 74% for Luck 6-8, 98% for Luck 9+.
  • rnl(35)<X (where X is average(str,dex,con) plus dex if you are Samurai or Monk) is the chance that you can kick down a door[16]. Odds are approx ((Luck+X)*2.9)+.1% for negative luck, 99.9-((35-(Luck+X))*2.9)% for positive luck, that is, almost impossible at low luck and low stats, almost certain at high luck and high stats + martial class.
  • rnl(20)<X (where X is average(str,dex,con)) is the chance that you can open a door[17]. Odds are approx ((Luck+X)*5)+.1% for negative luck, 99.9-((20-(Luck+X))*5)% for positive luck, that is, almost impossible at low luck and low stats, almost certain at high luck and high stats.
  • 200-rnl(101) is the gold left from a gold golem's death[18]. The difference in -13 and +13 luck is an extra 24 gold on average.
  • rnl(3)>0 is the chance that you are petrified if your saddle slips off[19] or is detroyed(?), or you are polymorphed and lose stone resistance[20], and are riding a steed that petrifies on touch. 99% at Luck<-3, 67% at -2<=Luck<=2, 34% at Luck 3-5, 1.5% at Luck 6 up to 1.75% at Luck 13 (the most obvious instance of an integer arithmetic quirk in the function, this slight variance exists in most of the high and low luck chances, but is usually far smaller).
  • rnl(5)>0 is the chance of a random levelport when attempting to controlled levelport (or cancel) while confused[21]. 99.7% at Luck<-2, 80% at -2<=Luck<=2, 60% at Luck 3-5, 41% at Luck 6-8, 22% at Luck 9-11, 2% at Luck 12+.
  • rnl(4)==0 is also the chance that blessed equipment is not eroded by rust[22] or water[23] damage, or blessed flammable items are not burned by fire damage[24]. .5% for Luck<-2, 25% for -2<=Luck<=2, 49% for Luck 3-5, 74% for Luck 6-8, 98% for Luck 9+.
  • rnl(5)>0 is also the chance that a monster becomes angry when it steps in a trap set by you[25], or that you trigger a trap when failing to disarm it[26]. 99.7% at Luck<-2, 80% at -2<=Luck<=2, 60% at Luck 3-5, 41% at Luck 6-8, 22% at Luck 9-11, 2% at Luck 12+.
  • rnl(10)<8 is the chance that a hostile, awake, unfrozen, mindful, nonhuman monster becomes peaceful when you free it from a trap[27]. 1% at Luck<-7, 11% at Luck -7, 21% at Luck -6, 70% at -5<=Luck<=-3, 80% at -2<=Luck<=8, 99% at Luck 9+.
  • rnl(8)==0&&rn2(3)==0 is the chance that a lawful player gets +1 alignment for the above[28]. rn2(3)==0 is a 33% chance, yielding overall odds of approx 1% at Luck<-2, 4% at -2<=Luck<=2, 6% at Luck 3-5, 12% at Luck 6-8, 16% at Luck 9-11, 20% at Luck 12+
  • rnl(10)<3 is the chance that a player gets +1 alignment for trying and failing to lift a hostile, mobile, mindful, nonhuman monster out of a pit not dug by you[29]. 1% at Luck<-5, 20% at -5<=Luck<=-3, 30% at -2<=Luck<=2, 40% at Luck 3-5, 50% at Luck 6-8, 59% at Luck 9-11, 69% at Luck 12+.
  • 50-rnl(50) is the number of darts/arrows/etc left behind when disarming a trap[30]. The difference in -13 and +13 luck is an extra 22 darts on average, relatively smootly distributed.
  • rnl(4)==3 is the chance that a boomerang will break when used as a melee weapon[31]. 99% for Luck<-2, 75% for -2<=Luck<=2, 51% for Luck 3-5, 26% for Luck 6-8, 2% for Luck 9+.
  • rnl(50)==49 is the chance that a successful joust, against a solid monster, breaks your non-artifact lance[32]. 28% at Luck -13 down to 2% at Luck 0 (smooth decrease), .03% at Luck 1 up to .05% at Luck 13 (another instance of the quirk).

Mathematical analysis

rnl, while not even in the same league as rnz, accomplishes it's 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.

Also, there is a 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


This page may need to be updated for the current version of NetHack.

It may contain text specific to NetHack 3.4.3. Information on this page may be out of date.

Editors: After reviewing this page and making necessary edits, please change the {{nethack-343}} tag to the current version's tag or {{noversion}} as appropriate.