Random number generator

From NetHackWiki
Revision as of 21:47, 24 October 2020 by Phol ende wodan (talk | contribs) (fix minor grammar issue)
Jump to navigation Jump to search

NetHack uses a random number generator (RNG) to determine the outcome of in-game events. Probabilities are expressed in d notation, a homage to Dungeons and Dragons.

Deification

The RNG is sometimes referred to as the Random Number God. The RNG plays a pivotal role in determining the fate of all characters, and is sometimes considered the deadliest enemy in the game, despite the fact that expert players such as marvin have demonstrated that nearly every game is ascendable.

Technical details

Although NetHack relies on the C rand() function, random number generation is not as straightforward as picking a number between 0 and n. Rnd.c holds all of the game's RNG functions, which can return results that depend on your Luck or experience level. Source divers might profit from examining these functions.

Misuse

3.4.3

It was found by Adeon that a sufficiently determined player can find the seed of RNG after starting the game and then use it to his or her advantage - for example to gain unlimited number of wishes from a fountain. For demonstration see his ttyrecs on NAO from 2009-02-28 (starting with http://alt.org/nethack/trd/?file=http://alt.org/nethack/userdata/A/Adeon/ttyrec/2009-02-28.10:31:15.ttyrec.bz2#). See also Sartak's blog entry Predicting and controlling NetHack's randomness and ais523's description of a game relying on extreme RNG manipulation.

Instead of taking the current time in seconds as seed, NAO has after this exploit been changed to read the seed from the operating system's own pseudorandom number generator '/dev/urandom'. This way the seed has become unpredictable.

To also complicate the deducing of the random number generator's internal state, periodic reseeding has been implemented.

UnNetHack

The player nht produced a 363 turns, 16 seconds set seed UnNetHack ascension by exploiting a known bug. Nht gave detailed report on this ascension in a reddit post.

3.6.1

A tool assisted speedrun exploiting the RNG has been done NetHack 3.6.1 by pellsson on NAO in 7 minutes and 15 seconds and 2087 turns.

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.