The Random Number Generator

Heikki

Chieftain
Joined
Aug 11, 2002
Messages
15
Location
Finland
There has been some discussion on the quality of the Random Number Generator (RNG) in Civ3 around the forum. I'm not sure if there's been a dedicated thread, but here goes.

People often comment that 'impossible' events occur in their games, like a spearman beating a tank or a long streak of hits going to the same direction. I'm not addressing the historical accuracy of such events here, but simply the mathematical probabilities of them taking place considering the combat rules in the game.

Instead of theorizing the whole thing, I'll create a few series of truly random numbers at www.random.org to see how things should work.

I'll create three samples of 100 numbers for a 2-1 odds situation (roughly corresponding to archer attacking and unfortified 1-defense unit on a grassland tile) and another three samples for a 10-1 odds situation (roughly corresponding to a modern armor attacking a fortified spearman on a grassland tile).

The results:

2-1 odds:

First round: 59-41 distribution, longest streaks 7 and 4*
2nd round: 69-31, 12 and 5
3rd round: 58-42, 8 and 5

10-1 odds:

1st round: 94-6, 29 and 1
2nd round: 89-11, 20 and 3**
3rd round: 83-17, 26 and 2

* including a streak of nine hits out of which 8 went against the odds - corresponding to an army of 3 regular archers being a able to scratch an unfortified warrior on a grasslands only once - it happens, people!

** corresponding to a spearman taking out a regular moder armor without a scratch

There you have it. Not a big test sample, sure, but gives you a bit of an idea how truly random series of numbers *do* include weird streaks and sometimes a pretty unbalanced distribution.

Oh, and in case you were wondering: I did not pick 'suitable' results, but ran only six tests, deciding beforehand the mapping from the numbers to the probability space. I used numbers from 1 to 3 for the first test, using 3 as a hit against odds and 1 to 10 for the second, using 10 as a hit against the odds.

Heikki
 
In any series of random numbers there will always be the possibility of strange sequences happening - like you indicate (nice reasoning/test) which in the game can lead to some weird combat results.

Also I remember learning that no computer can ever produce truly random numbers - they work from a seed number (the current time or something like that) and apply a formula and series of mathematical steps to generate a pseudo-random number which tends to further increase the likelyhood of the 'random number' generating strange results as it is not entirely random. Given enough people playing the game and posting here it is not surprising that sometimes strange things get reported.

Still it makes for interesting discussion in CFC about spearmen/tanks etc
 
Hawkster,

it's true that the RNG is not truly random. For the purposes of the game, though, I'm confident it's random enough to yield results that are not in any way distinguishable from true randomness.

Of course, sometimes people seem to think that one single weird streak is evidence of the RNG not being sufficently close to true randomness. :) As we know, in reality, if those streaks didn't *ever* occur, *that* would be evidence that the RNG is a bad one.

Heikki
 
Heikki: You did an interesting test, and I especially like that your conclusion is exactly what I have argued all the time :D

Hawkster, you are correct that the numbers aren't random in a RNG. It simply uses a (very advanced) formula to predict the next number from thr previous one.

However, the formula it uses should (and is) made so that it simulates real random numbers as close as possible - this means that the likelyhood of the 'random number' generating strange results is no higher than if you had real random numbers.

As Heikki shows, real random numbers are more streaky than humans expect. So when the RNG generates perfectly natural streaky strings, we think the RNG is to blame while it actually is our own expection that is faulty.
 
Assuming a discrete random result (such as a coin flip), there will be strings of arbitrary length of the same result. In other words, if you flip a coin long enough, sooner or later you will get a hundred heads in a row. In Civ3 terms, in 6,000,000 years of game play (100 players * 10 games * 6,000 years), almost anything can happen.

When flipping a coin, at some point heads (or tails) will be ahead. Once ahead, it will tend to stay ahead in the near term. That means that some people will appear to be lucky :) (and other players will appear to be unlucky :( ). But just because you have been lucky (or unlucky) so far has absolutely no bearing on your future luck.

Due to how the mind works (actually all neuronic activity), people observe the unusual and ignore the usual. That means they will remember the rare events and discount the common ones. This perception is often called "luck." A poor gambler relies on "luck." A good gambler relies on odds; and in a game of psychology like poker, takes advantage of the poor gambler's reliance on "luck."
 
In your second example you neglect the fact that modern armour can retreat. Regular Modern Armour will retreat approximately 50% of the time on 1 HP, so you in fact get 3 possible outcomes:

10-1 odds:

WIN-RETREAT-LOSS

1st round: 94-3-3
2nd round: 89-5-6
3rd round: 83-8-9
 
Mydisease,

The results I posted simply summarized the results of coming up with a series of 100 random numbers ranging from 1 to 10. The scenarios where provided to make the results more interesting to the average CivFanatic.

Granted, the modern armour example didn't take into account retreating. This, however is beside the point of the discussion, the RNG. I don't see how you came up with the series of numbers in your post.

Heikki
 
Sorry, I assumed only losses would go to retreats and forgot about the 1/3 of the wins that should as well. And as I'm tending towards the age old debate of Spearmen versus Modern Armour, I'll stop. I just wanted to make the point that the picture isn't as bleak as the results seem.
 
Most likely the random number generator that is used in civ3 is the standard random number gen.

One of the best, if not the best, random number generator has been devised by Stephen Wolfram for his program Mathematica .

It is completely un-analyzeable. There are no patterns. As soon as you find a pattern, it seems to dissapear. However, you can reproduce the results given the same seeds.

It uses pyramid-like cellular automata, given seed A, to give either a 0 or 1 result, depending on whether the middle cell is 0 or 1 on step A. It creates seed A from some things such as the timer and other various computer conditions.
 
Top Bottom