, 11 tweets, 3 min read Read on Twitter
1/ This question asks: "why would you want a non-random random function". This is a common thing, so I thought I'd explain it.
2/ One example is games, like NetHack or the 3D version from Blizzard known as "Diablo". In the game, you descend many layers into dungeons and fight monsters. The map for each level consisting of rooms and tunnels is laid out "randomly".
3/ Only it's not "random". A single 32-bit random number is used to 'seed' a predictable sequence, which determines how hundreds of levels and thousands of rooms are laid out. Saving the game means only saving that one number.
4/ Consider 'masscan', a tool that scans the entire Internet. You can pause scan in the middle and then continue it later. Like NetHack, it doesn't save a list of 2 billion addresses it has left to scan when you pause it.
5/ Instead, it saves the 'seed' used to create the random sequence of IP addresses, and the current index (some number between 0 and 4-billion). All you need to resume the scan in the middle is those two numbers.
6/ (I should mention: when you scan a range of addresses, it does so in random order).
7/ So you ask "You mean you based the design of an Internet-scale port scanner on NetHack?"

Yes. Yes I did.
8/ Unit test code does this a lot as well. Let's say that you are testing some complex number crunching code that processes gigabytes of input. You 'seed' that with a random number generator, that generates the data, and verify that the answer comes out to the expected value.
9/ Over time, as you maintain the code base, fixing bugs, adding features, any input with that seed should always create the same output value. So you see this "non-random random numbers" used everywhere in unit tests.
10/ Here's a screenshot of starting masscan of the entire Internet and hitting <ctrl-c> to pause it a second after it started, after it's already scanned 152 random IP addresses. As you can see, it needs to remember only the 'resume-index' and the 'seed', not which addresses.
11/ The 'seed' and 'index' are 64-bit numbers, which is why it appears to be such a large number. Yes, I get that seed from /dev/urandom, but I also xor in nanosecond-scale timestamps to make sure it's random.
Missing some Tweet in this thread?
You can try to force a refresh.

Like this thread? Get email updates or save it to PDF!

Subscribe to Robᵇᵉᵗᵒ Graham
Profile picture

Get real-time email alerts when new unrolls are available from this author!

This content may be removed anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Follow Us on Twitter!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!