RNG: Difference between revisions

From The Urban Dead Wiki
Jump to navigationJump to search
m (God —> Goddess)
(FA Nomination unsuccessful)
 
(13 intermediate revisions by 10 users not shown)
Line 1: Line 1:
'''RNG''' stands for '''R'''andom '''N'''umber '''G'''enerator. It is the device that allows [[Kevan]] to institute 'random chance' actions and determines success or failure for all actions. 
:''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)]]''


It is sometimes called the '''R'''andom '''N'''umber '''G'''oddess, As the RNG often seems to be a living being intent on screwing people over.
'''RNG''' stands for '''R'''andom '''N'''umber '''G'''enerator. It is the device that allows [[Kevan]] to institute random chance actions and determines success or failure for all actions.


It is sometimes believed that the '''RNG''' will provide a linear success rate, 10 successes in 100 for a 10% skill/effect, 35 out of 100 for a 35% skill/effect, etc.  This is untrue.  '''RNG''' processes things in a sucess rate in accordance to Murphy's Law, divided by Moore's Law, multiplied by the Square Root of a Piece of Cake.  Moore`s law states that CPU processing speed will double every 18 Months, and Murphy's law states that what ever the worst thing is, it'll happen.  This means that every year-and-a-half computational beasts like the '''RNG''' will screw you over twice as much as they did before.  This is because the '''RNG''' is a cold-hearted bitch that will take your heart out as quick as look at you.  '''RNG''' will shaft you in ways that you didn't even know existed; we're talking Old Gods, The King in Yellow style abuse here.
==Introduction==


You may choose to believe the damn '''RNG'''.  This means you are a fool. '''RNG''' doesn't let you invest 5 searches into a hospital and give you an [[FAK#First_Aid_Kit|FAK]]. Lady Un-Luck is a chancy broad, and a chance is only a definite maybe, a possibility at best. Its a CHANCE, boys. 33% does not mean every third time a success, but it does mean for INFINITE counts of tries 1/3 will be successes.  
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.


Unfortunately, the RNG used by Urban Dead is not perfect.  It isn't even close to perfect. The number for a 33% chance should approach 1/3 the more you perform the action, but in fact, does not. This is because the RNG is actually a pRNG.  A Psuedo Random Number Generator.  And the pRNG used by Urban Dead is liable to give you strings of "bad luck" so horrible that were it a fair RNG, you might want to start thinking about dodging lightning.
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.


You ever search for a syringe 50 times and get 2?  Blame '''RNG'''. You get killed by three flareguns to the face one-after-the-other?  Blame '''RNG'''.
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).


As [[User:Petrosjko|Petrosjko]] once said: "There are good days, there are bad days, and there are ''break-out-the-KY-Jelly'' days."
==Common Human Fallacies==


In the Book of Useless Knowledge it is stated: "The chance to die after being kicked by a Donkey is actually far higher than dying during an Airplane chrash." (check global statistics) but '''RNG''' is that Mach Five Donkey Dive-Bomber that will take you out in the middle of a LAKE while you are celebrating your birthday.  Don't screw with '''RNG''' man, 'cause she's a Craftsmen Powerdrill and you happen to fit her Phillip's Head.
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'.


==Related==
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.
 
==The Urban Dead PRNG==
 
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 '''C'''ryptographically '''S'''ecure-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.
 
==See Also==
*[[wikipedia:Pseudorandomness|Pseudorandomness]] at the English Wikipedia - What exactly is it?
*[[wikipedia:Pseudorandom number generator|PRNGs]] at the English Wikipedia - Generators of such numbers.
*[[wikipedia:Statistical randomness|Statistical randomness]] at the English Wikipedia - Just how do you measure how 'random' a sequence is?
*[[Groove Theory]]
*[[Groove Theory]]


[[Category:Glossary]]
[[Category:Glossary]]
[[Category:Technical Information]]

Latest revision as of 04:17, 26 September 2012

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.

The Urban Dead PRNG

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.

See Also