Skip to content

Comment on Predicting and controlling NetHack's randomness (2009)

Comments

Unfortunately, a computer's pool of truly random numbers is very limited; it has to build up by measuring minute temperature changes or internal timing variations. NetHack, especially being played by fifty people on a public server, would keep that pool empty and harm the game's playability.

No, no, no. This is a horrible misconception.

It's easy to generate an effectively infinite stream of random numbers: use a block cipher in CTR mode (i.e., using the seed as the key, encrypt 0, then 1, then 2, then 3 and so on). All you need for this is a single truly-random seed, and from it you'll get 2^128 random numbers—far more than you will ever, ever need.

Now, how do you get that initial random seed? That's where the art comes in, but a basic version would simply hash all those truly-random input events (e.g. those temperature changes or internal timing variations) together. A more complex system, such as Schneier and Ferguson's superb Fortuna, uses a system of 32 pools, where the pools are used to periodically reseed the generator, in a clever fashion which can protect even against generator-state compromise.

And with modern chips, AES-256 in CTR mode is fast, really fast. Fortuna'd be perfectly usable in Nethack.

(As an aside, it'd also be perfectly usable as a replacement for the needlessly-complicated and insufficiently-grounded Linux CSPRNG underlying /dev/random and /dev/urandom).

For a game, fine, donk around with your own CSPRNG implementation; for real-world apps, please just use /dev/urandom.

The overwhelming majority of RNG disasters in the past decade have come from userland CSPRNGs written by people who were wary of urandom.

For a game, fine, donk around with your own CSPRNG implementation; for real-world apps, please just use /dev/urandom.

Sure. I just wish that /dev/urandom were well-thought-out rather than accidentally probably-good-enough.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.