Paradox Interactive Forums  

Go Back   Paradox Interactive Forums > Historical Games > Europa Universalis II

Reply
 
Thread Tools
Old 26-04-2003, 14:53   #1
mueller
Colonel
 
mueller's Avatar
 
Join Date: Apr 2003
Location: Kharkov province
Posts: 958
Peasants are never happy, or EU Random Number Generator

Played a couple of games for 50-100 years under 1.07beta (apr18 patch). Some observartions on random events:

Timurids:
3 "Political Crisis" in a row.
Followed by 4 "Plague!" (which under Apr18 patch was not a bad thing, as Isfahan became mongol-cultured);
Followed by 2 "Bad government policies";
Followed by 5 gifts.

Venice:
3 "Unhappiness among the Peasantry" (???! I was one tick towards Free Subjects";
Followed by 3 "Rush of merchants";
Followed by 5 "Support for dissidents abroad".

Russia:
3 "Unhappiness among the Peasantry";
Followed by 3 "Exceptional Year" (within 3 years);
Followed by 5 "New Land Claimed", all in Moscow;
Followed by 4 "Enthusiasm for the Navy", all in Greenland (which I've got off Norway).

Small sample, of course, but it just seems like random number sequences are heavily autocorrelated.

Could be bad random number generator (actually, default C rnd() function is notoriously bad)

Or maybe random events are not random at all, i.e. the code looks something like


i=1; // event counter
j=1; // province counter
for (; ; ) { // eternal loop
target_country=GetOwnerCountry(j);
wait(rnd());
TriggerEvent(target_country, i, j);
i++; j++;
if (i>MAX_EVENTS) i=1;
if (j>MAX_PROVINCES) j=1;
}


Since provinces change hands over time, their owner countries would be eligible for different events in a fairly unpredictable way, so this would create an illusion of randomness.

However, if political situation is relatively static for a long time, target_country would not change much and you will get the same random event over and over again, which seems to happen often.

What is your experience?

[Edit: modified code slightly]

Last edited by mueller; 26-04-2003 at 19:36.
mueller is offline   Reply With Quote
Old 26-04-2003, 18:09   #2
Alkar
Dark Lord wannabe
 
Alkar's Avatar
Diplomacy Player
 
Join Date: Oct 2002
Location: Deusone
Posts: 1,157
I am having similar experiences as well in my games, for example I have 30 years of no negative stab random events followed by a decade of massive upheavals having 3 unhappy peasantry events in a decade and some other nasty events thrown in for good measure. One of my most recent games under 1.07 beta saw me getting hit with 10 unhappy merchants events in 50 years time, I know this event is dp-related, but still this is quite a lot. I made hardly any progress in trade during that period.
__________________
My current HoI 2 DoomsDay AAR: Germany''s One Hundred Divisions Gamble
Alkar is offline   Reply With Quote
Old 26-04-2003, 19:19   #3
MJames
Second Lieutenant
 
MJames's Avatar
 
Join Date: Mar 2003
Location: Chicago, IL
Posts: 146
Same thoughts

I've had 6 "fires" in 100 years. For some reason my art academy in Anglia must be made of gas-soaked rags. After the 4th one I got so annoyed I just edited the file and gave it back. Then it burned down again.

My last game I kept getting plagues. Probably over a dozen during the entire game, but not one fire. Now, not a single plague but fires every other decade. I'm guessing they are tied to something, but not sure what.
MJames is offline   Reply With Quote
Old 26-04-2003, 19:27   #4
KwangTiger
The Maverick
 
KwangTiger's Avatar
 
Join Date: Jun 2002
Location: The land of the ice and snow with the midnight sun where the hot springs flow
Posts: 3,104
The worst are the political crisises. In my current game as Russia I have 4 out of my 5 slider religions, and being at -6 stab isn't very fun.
__________________
Wow
KwangTiger is offline   Reply With Quote
Old 26-04-2003, 20:37   #5
Quizzical
Colonel
 
Join Date: Jul 2002
Location: Earth, at least on even numbered days starting with T
Posts: 918
The big random number generation problem that I've seen is in discovering provinces with an explorer at naval tech below 18, which is not random at all. One in ten provinces that is sailed by will be explored, though this can be thrown off by the AI also sending explorers around. To demonstrate this, save a game with an explorer one day away from reaching a seazone that is adjacent to an unexplored province (and not more than one), and repeatedly load the game, let him reach the province, note whether he discovers it, then reload the game and try again. Unless some other explorer also tries to explore something, he'll discover the province every tenth time, though the first one could take fewer than ten tries.

Fortunately, it's not that hard to make a random number generator with properties suitable for the game. It's not absolutely vital that no one can discover what the random number generator is, as is the case, for example, with online gambling. Here's one that I use in a game I'm making in Visual Basic:

Code:
Public Prime As Long = (some prime number)
Public Root As Long = (some primitive root of the prime)
Public RSeed As Long = (a positive integer less than the prime)

Function Rand() As Double
    RSeed = (RSeed * Root) Mod Prime
    Return CDbl(RSeed) / CDbl(Prime)
End Function
I use a nine digit prime number so that it doesn't repeat quickly. You could also have the random seed saved in the save game file so that repeatedly reloading a game might give the same result every time unless you change your behavior. If you don't know what a primitive root of a prime number is, then take a number theory class.
__________________
Free speech is not limited to those who have something intelligent to say.
Version 1.06, no mods
Completed grand campaigns with: Algiers, Auvergne, Cambodia, Castile/Spain, Cologne, Dakota, Hungary, Hyderabad, Kongo, Mantua, Ragusa, Qara Koyunlu, Wallachia
Quizzical is offline   Reply With Quote
Old 26-04-2003, 20:37   #6
Neuro
Captain
 
Neuro's Avatar
 
Join Date: Apr 2003
Location: 15 VII 1410 Tannenberg... right flank
Posts: 358
Playing Scotland right now... it's 1500 and within the last 20 years I had 5 or 6 Political Crisises... earlier I had massive Rush of Marchants (3 or 4 times)....

Obviously there's something wrong with the random number generator... and there's nothing we can do about it... but there's someone who can
__________________
War is not about who is right, it's about who is left.
Anders Russel
Neuro is offline   Reply With Quote
Old 26-04-2003, 20:39   #7
DGuller
Major
 
DGuller's Avatar
Hoi2 Beta MemberEU3 Complete
 
Join Date: Feb 2003
Posts: 644
What do you mean, -6 stab? Aren't you limited to -3? Also, I noticed the same thing playing Manchu, political crisis was the norm of these days, I've had at least 5 in close succession. If those events really are random, then random generator needs a good upgrade.
DGuller is offline   Reply With Quote
Old 26-04-2003, 20:40   #8
KwangTiger
The Maverick
 
KwangTiger's Avatar
 
Join Date: Jun 2002
Location: The land of the ice and snow with the midnight sun where the hot springs flow
Posts: 3,104
Whoops! I meant -3 stab.
__________________
Wow
KwangTiger is offline   Reply With Quote
Old 26-04-2003, 20:42   #9
DGuller
Major
 
DGuller's Avatar
Hoi2 Beta MemberEU3 Complete
 
Join Date: Feb 2003
Posts: 644
Quote:
Originally posted by Quizzical
The big random number generation problem that I've seen is in discovering provinces with an explorer at naval tech below 18, which is not random at all. One in ten provinces that is sailed by will be explored, though this can be thrown off by the AI also sending explorers around. To demonstrate this, save a game with an explorer one day away from reaching a seazone that is adjacent to an unexplored province (and not more than one), and repeatedly load the game, let him reach the province, note whether he discovers it, then reload the game and try again. Unless some other explorer also tries to explore something, he'll discover the province every tenth time, though the first one could take fewer than ten tries.

Fortunately, it's not that hard to make a random number generator with properties suitable for the game. It's not absolutely vital that no one can discover what the random number generator is, as is the case, for example, with online gambling. Here's one that I use in a game I'm making in Visual Basic:

Code:
Public Prime As Long = (some prime number)
Public Root As Long = (some primitive root of the prime)
Public RSeed As Long = (a positive integer less than the prime)

Function Rand() As Double
    RSeed = (RSeed * Root) Mod Prime
    Return CDbl(RSeed) / CDbl(Prime)
End Function
I use a nine digit prime number so that it doesn't repeat quickly. You could also have the random seed saved in the save game file so that repeatedly reloading a game might give the same result every time unless you change your behavior. If you don't know what a primitive root of a prime number is, then take a number theory class.
LOL, somebody's trying to impress with his mathematical knowledge today.
DGuller is offline   Reply With Quote
Old 26-04-2003, 22:27   #10
mueller
Colonel
 
mueller's Avatar
 
Join Date: Apr 2003
Location: Kharkov province
Posts: 958
Quote:
Originally posted by Quizzical
The big random number generation problem that I've seen is in discovering provinces with an explorer at naval tech below 18, which is not random at all. One in ten provinces that is sailed by will be explored, though this can be thrown off by the AI also sending explorers around.
It is fairly common that some allegedly "random" effects are not random at all. As an example, in Civ II switching governments triggered a period of "anarchy" for a (presumably) random number of years. Well, it was eventually discovered on Apolyton forums that the length of the anarchy period was a simple function of the game turn number. Since each game turn in CIV corresponds to different number of years, and since the turn number was not displayed anywhere in the game, this was not an obvious thing to find out... Once it was discovered, though, tables were made for "safe" years to switch governments, and anarchy became a non-issue...

I suspect it might be something similar with random events in EU (as per code in the first post...)
mueller is offline   Reply With Quote
Old 26-04-2003, 22:28   #11
Johan
The Master
Paradox Dev Team
 
Johan's Avatar
Diplomacy PlayerEU3 Collectors Edition OwnerNapoleonic MarshalEuropa Universalis III: In NomineEU3 Complete
Heir to the Throne
 
Join Date: Dec 1999
Location: Always two there are...
Posts: 12,564
Plenty of stuff are not truely random, simply because they are processed locally and not on the server.
__________________

Johan Andersson
Wizard

"A patch is never late! Nor is it ever early. It arrives precisely when I mean it to do!"
Johan is offline   Reply With Quote
Old 26-04-2003, 22:34   #12
mueller
Colonel
 
mueller's Avatar
 
Join Date: Apr 2003
Location: Kharkov province
Posts: 958
Quote:
Originally posted by Johan
Plenty of stuff are not truely random, simply because they are processed locally and not on the server.
Wow! A reply from Johan! Now if I could only understand what does it mean, maybe there is a chance to pacify these peasants after all
mueller is offline   Reply With Quote
Old 26-04-2003, 22:36   #13
DarthMaur
Grandpa Maur
 
DarthMaur's Avatar
EU3 OwnerEuropa Universalis: Rome
 
Join Date: Apr 2001
Location: Warsaw, Poland
Posts: 7,818
Re: Same thoughts

Quote:
Originally posted by MJames
I've had 6 "fires" in 100 years. For some reason my art academy in Anglia must be made of gas-soaked rags. After the 4th one I got so annoyed I just edited the file and gave it back. Then it burned down again.

My last game I kept getting plagues. Probably over a dozen during the entire game, but not one fire. Now, not a single plague but fires every other decade. I'm guessing they are tied to something, but not sure what.
The game doesn't like you?
__________________
Polyamory? And now also the (shorter, but expanding lately!) Polish version!

Androgynous atheist bisexual feminist liberal libertine polyamorous transhumanist switch.
DarthMaur is offline   Reply With Quote
Old 26-04-2003, 23:12   #14
clb
Mostly Lurking
 
clb's Avatar
 
Join Date: Mar 2001
Location: CA, USA
Posts: 379
Quote:
Originally posted by Quizzical

Code:

Public Prime As Long = (some prime number)
Public Root As Long = (some primitive root of the prime)
Public RSeed As Long = (a positive integer less than the prime)

Function Rand() As Double
    RSeed = (RSeed * Root) Mod Prime
    Return CDbl(RSeed) / CDbl(Prime)
End Function
I use a nine digit prime number so that it doesn't repeat quickly. You could also have the random seed saved in the save game file so that repeatedly reloading a game might give the same result every time unless you change your behavior. If you don't know what a primitive root of a prime number is, then take a number theory class.
Actually, the selection of the values for a random number generator is not simple, and the geekly are referred to Knuth's _The Art of Computer Programming_, Volume 2.
__________________
-chris bond

Last edited by clb; 27-04-2003 at 00:00.
clb is offline   Reply With Quote
Old 27-04-2003, 01:50   #15
Peter Ebbesen
the Conqueror
 
Peter Ebbesen's Avatar
Hoi2 Beta MemberEU3 Collectors Edition OwnerNapoleonic MarshalEuropa Universalis: RomeEuropa Universalis III: In Nomine
Rome: Vae VictisMajesty 2
 
Join Date: Mar 2001
Location: Beyond the infinite
Posts: 12,607
Quote:
Originally posted by Quizzical

I use a nine digit prime number so that it doesn't repeat quickly.
Considered using a Tausworth generator instead, or is that too periodic for you? ()
__________________
When I said: "Death Before Dishonour!", I meant it alphabetically.

-----

For new denizens of the forum: To post here you have already agreed to follow the user agreement and the general rules (pay specific attention to rules 2, 3, and 6 if writing while your temper is heated). Furthermore, there may be special rules for specific forums. These can usually be found in sticky posts at the top of a forum. Read the stickies and obey the rules and, overall, it is a much nicer forum for all of us. Disobey the rules and be moderated, warned, put on probation, or banned.
Peter Ebbesen is offline   Reply With Quote
Old 27-04-2003, 01:58   #16
boehm
Danish Guy
 
boehm's Avatar
 
Join Date: Oct 2001
Location: Aarhus, Denmark
Posts: 2,327
Quote:
Originally posted by Peter Ebbesen
Considered using a Tausworth generator instead, or is that too periodic for you? ()
ok I feel lost....anybody else?!

(I should probably stick to the threads talking about economic issues...not programming issues)
__________________
Currently spending my time on ... Empires in Arms & Mordheim ...
boehm is offline   Reply With Quote
Old 27-04-2003, 02:04   #17
Quizzical
Colonel
 
Join Date: Jul 2002
Location: Earth, at least on even numbered days starting with T
Posts: 918
My point was that a good random number generator for various purposes didn't need to be complicated. What I posted would work for some purposes, and most likely for EU2, though it would be quite bad for others. In particular, the values it generates at once step would be uncorrelated with the values any reasonable number of steps later. For the purpose I needed it for, repeating quickly would have been quite bad, hence the choice of a primitive root.
__________________
Free speech is not limited to those who have something intelligent to say.
Version 1.06, no mods
Completed grand campaigns with: Algiers, Auvergne, Cambodia, Castile/Spain, Cologne, Dakota, Hungary, Hyderabad, Kongo, Mantua, Ragusa, Qara Koyunlu, Wallachia
Quizzical is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT +1. The time now is 22:19.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
© Copyright 2001-2009 Paradox Interactive