# Random Number Generator

The **Random Number Generator**, or **RNG**, is the section of server-side code that generates random numbers for use in any game formulas that involve probability or odds, such as loot generation.

## Pseudo-Random

The RNG is more accurately a *pseudo*-random number generator; I.e. it uses an algorithm that is only capable of producing a sequence of numbers that *appear* random. The algorithm takes a starting number, known as a "seed" or "seed state," and uses it to populate a predetermined formula, which is then evaluated. The number output by this formula is then used to repopulate the same formula, which is then evaluated again. This process is repeated many times to create the sequence of pseudo-random numbers.

## Streakiness

Many players complain that the RNG seems to produce overwhelmingly positive or negative strings of results based on time of day, in-game location, specific account used, etc. There are several different reasons for this.

### Normalization

Since the majority of systems that rely on probability do it based off of a percentage chance, which works on a scale of 0.0-1.0, and most RNG algorithms output numbers on scales many orders of magnitude greater than this, these numbers need to be normalized down to be of any use.

This means that if the RNG outputs 920,008,239 and 924,999,908, these numbers get normalized to 0.920008239 and 0.924999908, respectively. These are then rounded to 0.92 and 0.92, respectively, which are, quite obviously, the exact same value. This means that it is possible for the RNG to generate a series of fairly disparate numbers (in this case, two numbers that are 4,991,669 apart) that are all normalized down into the exact same value, resulting in an apparent streak.

### Periodicity

The length of the number sequence generated by a particular algorithm before the sequence comes back around to the original seed number and begins repeating, known as the algorithm's "periodicity," is largely determined by the bit-size of the seed (32-bit, 64-bit, 128-bit, etc.), as well as the complexity of the algorithm's formula. Since UO was originally created in the mid- to late-nineties, a time when memory and processing power in computers was a mere fraction of what it is today, many values are stored as smaller bit-sizes and many algorithms are purposefully simplistic. This would result in a relatively short periodicity, which, when combined with the aforementioned normalization problem, could lead to even longer streaks.

### Location/Time

It was once stated by Draconi, after he looked through the RNG code, that each sub-server on a shard apparently has its own RNG that generates all of the random numbers required on that sub-server. This means that the RNG itself could not be experiencing a streak, but the subset of its sequence that any one player receives may be viewed as such.

For instance, consider the following sequence: **39**, *65*, 99, 18, *69*, **33**, 87, 12, *60*, 23, **30**, 78. One player may be receiving only the bolded numbers (39-33-30), and another only the italic numbers (65-69-60). Each player receives a sequence of very similiar numbers, and thus sees a repeated outcome. The overall sequence is fairly random, but for each player, they receive only a streak.

### Perception

Many systems lend themselves to a general perception of streakiness due to their inherently dichotomous nature. A player may be attempting an action that will result in only a success or a failure based on a certain probability threshold. Any values generated below this threshold result in failure, and any above this threshold are success.

For example, consider a player attempting an action that has a 50% success rate 8 times in a row. From the RNG, they receive the following sequence: 49, 0, 23, 12, 34, 98, 52, 66. The first 5 numbers are below 50, so they result in failure. The last 3 numbers are above 50, so they result in success. This sequence of 8 fairly random numbers results in two streaks in a row due to the pass/fail nature of the action.

Another perception problem stems from the fact that human beings are inherently bad at accurate estimation in probability-based situations, such as risk-assessment and gambling odds. A player may attempt an action that has a 95% success rate, fail four times in a row, believe that this is a highly unlikely turn of events, and declare the system a failure, claiming that the RNG "hates" them.

Players see the word "Random" and take that to mean that each roll will be wildly different than the last, as though each roll affects subsequent rolls to prevent similar outcomes from clumping together. The odds of rolling a 0 twice in a row is the same as the odds of rolling a 52 and then a 96, or a 1 and then a 2, or a 66 and then a 12. Each attempt is an independent, non-deterministic event, causally unrelated to all previous attempts.