# RNG

This page is about the Random Number Generator (RNG) and is is generally relevant and sometimes even factual. If that sickens you and you miss the old-school fire-and-plagues version of this page, see RNG (Old Testament). For other uses, see RNG (Disambiguation)

RNG stands for Random Number Generator. It is the device that allows Kevan to institute random chance actions and determines success or failure for all actions.

## Introduction

RNGs are not limited to computers; the action of flipping a coin can generate random numbers. Quantum Mechanics currently states that interactions between the fundamental particles of the universe are dependent on random outcomes.

Technically, Urban Dead uses a PRNG, a computer algorithm to generate pseudorandom numbers. These numbers are created from a predictable sequence, but in a fashion that is used to produce results that appear as random as possible, hence pseudorandom. PRNGs differ from 'true' RNGs in that their results will always repeat (albeit after very long sequences of numbers) and that the result can always be determined given the state of the PRNG.

The state is the current setup of the PRNG in regards to where it is in terms of outputting numbers. This is determined by a seed which is input into the algorithm and then used iteratively to churn out random numbers. A PRNG will always produce the same sequence of numbers from a set state. The larger the number of possible values for your seed, the harder it is to guess which sequence you might be using. A common seed value is based on the time (usually microseconds).

## Common Human Fallacies

Humans are really very bad are generating random sequences. We are pattern-seeking creatures and thus tend to be jaded when it comes to things that are random. Ask anybody for a random sequence of 10 coin tosses and they will probably come up with something along the lines of 'HHTHTTTHHT'.

This isn't a particularly 'random' sequence, there is an even split of heads/tails and repeats are short in length. A more 'random' sequence might be 'HHHHHTHTTH'. with an uneven distribution of heads and tails, and much longer repeat lengths.

Remember that any single sequence is as likely as the next: the sequence 'HHHHHHHHHH' is just as likely as either of the two above!

In the context of Urban Dead, this is why players shouldn't be surprised when their 50% success rate attack misses 5x in a row. When dealing with small sample sizes - anything less than hundreds, if not thousands, of attacks - such events are not particularly out of the ordinary.

While it is true that a good PRNG should converge to a given result over time (in this case, to a 50:50 hits v misses) you would need to perform thousands, if not millions of tests before any statistician worth their salt raised an eyebrow at your 60:40 split.

Good PRNGs must pass batteries of test for statistical randomness which rely on mathematics that most of us will never meet. Good PRNGs are usually able to produce millions of random numbers very quickly, and will pass most, if not all, tests comfortably. The best PRNGs are CSPRNGs, or Cryptographically Secure-PRNGs. Because of their importance, their randomness is essential; if an attacker can spot a pattern, he may be able to break the cypher. These are far and few between.

The Urban Dead PRNG is neither a CSPRNG, or even a decent PRNG.

It uses the php srand() function[citation needed] (seeded-random number generation: the seed goes in the brackets and then a sequence of random numbers can be produced), which fails badly at being random. It fails so badly in fact that even a mere human can spot the pattern without much difficulty. In Urban Dead, it was seeded with Unix Time (The numbers of seconds elapsed since Jan 1st, 1970).

For casual uses like video games, seeding with microseconds is usually enough, people are only concerned with the results and can hardly choose the exact microsecond to click.

Seeding with seconds means that any user can almost guarantee the seed, they have a good margin for error. If a flaw exists in the algorithm, this can be easier to exploit in real time. srand() has some weak seeds - these are seeds that produce distinctly 'nonrandom' number sequences.

One exploitation of this admirably poor generation of numbers exists in the form of Groove Theory. It uses the exploitation of a weak seed which occurs at intervals of eight, which tended to produce a similar sequence of numbers. If a player performed an action on these intervals, he or she could almost be assured of the 'random' number received back. Groove Theory has been fixed, but it is unknown how predictable the system that replaced it is.