• We are currently performing site maintenance, parts of civfanatics are currently offline, but will come back online in the coming days (this includes any time you see the message "account suspended"). For more updates please see here.

What RNG does Civ use?

Aardvark

Chieftain
Joined
Mar 4, 2005
Messages
49
Location
Northern Virginia
Does anyone know what PRNG Civ uses? Even what type would be helpful. Some types of PRNG are more likely to have long strings of similar numbers.
 
Not so much mad as curious. I have an ops research kind of job. Suits my nature to ask questions. I have been exploring PRNGs for repeatable parallel simulations, lately, so just wondered.
 
I made my own RNG. It seems random enough, as I tested it several times.
 
I doubt the Civ RNG is very scientific. A lot of game programmers do insatities such as getting the modulo of a pseudo random number in order to adjust its range, and just leave it at that because it "seems random enough". If you know a little about the subject you should see why this is obviously very bad.
 
I think its pretty much established the Civ RNG has a tendency towards strings. If it was deciding the outcome of a coin flip, for example, and it lands heads, its more likely to land heads next time. But it hits tails sooner or later, and then its more likely to see more tails, so it balances out in the long run. But not very good at being random.
 
If you do a search, you will find that the PRNG used by Civ3 has been demonstrated to be *very* accurate at representing true random numbers. People have a tendency to think random numbers should not be "stringy", when, in actuality, they can be very much so.
 
Padma said:
If you do a search, you will find that the PRNG used by Civ3 has been demonstrated to be *very* accurate at representing true random numbers. People have a tendency to think random numbers should not be "stringy", when, in actuality, they can be very much so.
I'm too lazy to do a search, but I beleive you. The reason why people think random numbers should not be "stringy" is because they forget that each trial is independent and generalize the rules of infinite sets to finite ones.
 
Bungus said:
I think its pretty much established the Civ RNG has a tendency towards strings. If it was deciding the outcome of a coin flip, for example, and it lands heads, its more likely to land heads next time. But it hits tails sooner or later, and then its more likely to see more tails, so it balances out in the long run. But not very good at being random.
That is completely false. Please see my previous post.
 
Bungus, it may feel like that, but I believe that's because people tend to remember a string of bad / good lucks more than a well... oscillating one. It's like Padma said, string can occur and still the outcome set can be called random. It is however not a general rule that strings have to occur... If that ain't random, I don't know what is.

People are generally very poor in creating random strings themselves. They try so hard to have no sequence in it, that the randomness is destroyed by this.
 
I believe Oystein reverse-engineered the PRNG at one point. It's extremely accurate, and has been demonstrated to be very VERY good at mimicking true random numbers. The fact that people are so bad at generating anything even close to a truly random string is not its fault. In fact, were it designed to comform to what people expect of randomness instead of true randomness, it would be easily abusable AND significantly less random.

Arathorn
 
Civ3 uses a common multiplicative linear congruential prng.
You can find the same prng in the standard library for C.

Here is a java implementation:
Code:
public class Random {
    public int seed = 0;

    public int rnd() {
        seed = seed * 1103515245 + 12345;
        return ((seed >> 16) & 0x7FFF);
    }
}
In combat calculation, integral division by 32 is used. So there are only 1024 possible numbers compared to 32768 for other calculation.
 
Brain said:
That is completely false. Please see my previous post.
Now if you're saying this "coin flip" RGN is good solely because on a long enought time-line the number of heads and tails are equal, that is false. You should not be more likely to see tails after tails has come up, or vise versa. That would create strings, but when heads finally comes up, the strings would be reversed in heads favor. This would, with a large enough sample, show equal chances of heads vs. tails. But if the previous outcome effects previous ones, well, that would make for a bad (predictable) RNG.

But, it seems we've reached the general consensus this is not the case with Civ3's RNG. I'm not entirely convinced, but its not so extreme as to significantly degrade gameplay.
Although perhaps it may just be the AI cheating on higher difficulty levels..

By the way, how do you reverse engineer Civ's PRGN without the source code?
 
Sorry to say it, but the AI has also been demonstrated not to cheat in combat, on any level. Plenty of people have done the good old empirical "bash 10,000 warriors into 5000 hoplites" sort of tests, and the results have always matched expectations.

Renata
 
I don't buy it.
Anybody who says they sat there and watched 10,000 fights between a spearman and, whatever, is either crazy or a liar.
 
There are some crazy peole out there. It happened.

BTW, it doesn't cheat on die rolls. Last I looked at it was using a linear congruential PRNG (the modulo one mentioned earlier) unless Andy snuck in that MT that he likes so much.
 
Bungus said:
By the way, how do you reverse engineer Civ's PRGN without the source code?
The seed value is stored in the save file. I looked at how it changed and tried to find a pattern. After some investigation I concluded that the number 12345 was central and made a google search including that number and the correct algorithm popped up.
 
Back
Top Bottom