• We have updated our Community Code of Conduct. Please read through the new rules for the forum that are an integral part of Paradox Interactive’s User Agreement.

KostasL

Dead already!
8 Badges
Jan 17, 2005
1.034
75
  • Arsenal of Democracy
  • Hearts of Iron II: Armageddon
  • Darkest Hour
  • 500k Club
  • Hearts of Iron IV Sign-up
  • Hearts of Iron IV: Cadet
  • Hearts of Iron IV: Death or Dishonor
  • Hearts of Iron IV: Expansion Pass
So...I added some tech triggered events...which are meant to be triggered randomly...with predefined chances that I set !

For example I have this event...


event = {
id = 40532
random = no
persistent = yes
trigger = { random = 50 }
name = "Research Project Success!"
desc = "New weapons and equipment for our AirForce!"
picture = "research-success"
style = 0
action_a = {
name = "Splendid!"
command = { type = air_defense which = escort value = 1 }
}
}

Random 50 means that it has 50 percent chances to trigger !

But it does not really work like this...

I have a tech which should trigger some 12 of these events...
Which means that sometimes I should get 4...sometimes 6...sometimes 8...etc

But it seems that I often get only the first event triggered...Only one event of twelve...And I test again and again getting this result for many consecutive times!
Other times I get all twelve events...
Other times it seems to work normally...o_O
 
Upvote 0
Welcome to std::rand(), which should never ever be used where one expects random numbers of a certain distribution.
Especially not modulo some number which RAND_MAX is not a whole multiple of.

... Only 59 instances left to replace with proper random number generation...
 
Welcome to std::rand(), which should never ever be used where one expects random numbers of a certain distribution.
Especially not modulo some number which RAND_MAX is not a whole multiple of.

... Only 59 instances left to replace with proper random number generation...

Well...as I cannot find a direct solution for this...I did this my way!

Instead of triggering many random events together...I trigger one extra pre-event for every single random event...

So instead of triggering 12 random events...I trigger 12 normal event...who each of them trigger only one random event!
It seems to work properly, now!
 
Mmh. That is interesting. There should not be a large difference.

Well...I did experiment a bit...and I had some interesting results which show a pattern in this abnormal behavior !

CASE 1.
I fired...20 times... 10 single random events with a 50% chance...using 10 single triggering events !

Each one of these events had a single command like this...
command = { type = trigger which = 40002 }

CASE 2
Then... I fired... 20 times...10 single random events with a 50% chance...using 1 only triggering event !

This event had 10 commands like this...
command = { type = trigger which = 40001 }
command = { type = trigger which = 40002 }
command = { type = trigger which = 40003 }
command = { type = trigger which = 40004 }
command = { type = trigger which = 40005 }
command = { type = trigger which = 40006 }
command = { type = trigger which = 40007 }
command = { type = trigger which = 40008 }
command = { type = trigger which = 40009 }
command = { type = trigger which = 40010 }


CASE 3
I fired... 20 times...10 single random events with a 50% chance...using 1 only triggering event !

This event had 10 random events triggering commands between 10 normal events triggering commands like this...
command = { type = trigger which = 50001 } normal event
command = { type = trigger which = 40001 } random event
command = { type = trigger which = 50002 } normal event
command = { type = trigger which = 40002 } random event
command = { type = trigger which = 50003 } normal event
command = { type = trigger which = 40003 } random event
command = { type = trigger which = 50004 } normal event
command = { type = trigger which = 40004 } random event
command = { type = trigger which = 50005 } normal event
command = { type = trigger which = 40005 } random event
command = { type = trigger which = 50006 } normal event
command = { type = trigger which = 40006 } random event
command = { type = trigger which = 50007 } normal event
command = { type = trigger which = 40007 } random event
command = { type = trigger which = 50008 } normal event
command = { type = trigger which = 40008 } random event
command = { type = trigger which = 50009 } normal event
command = { type = trigger which = 40009} random event
command = { type = trigger which = 50010 } normal event
command = { type = trigger which = 40010 } random event




THE RESULTS ARE ENLIGHTENING !

For these 10, .... 50% random events, numbered from 1 to 0....


In Case 1... I got these results :
1 2 5 6
2 4 7 8 9 0
1 2 3 6 9 0
1 2 5 6 7 8 9
2 3 6 7 8 0
1 7
1 3 4 5 8 9 0
1 2 4 5 7
2 6 8 9
2 3 6 8 0
3 4 7 8 0
3 5 7 9 0
1 3 6 7 8 0
3 6 9 0
2 5 7 8 0
1 2 3 4 6 8 9 0
1 4 5 8 9 0
1 5 7 0
2 3 4 6 7 9 0
2 3 6 7 8 9


In Case 2... I got these results :
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9 0
-
1 2 3 4
-
-
-
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
-
1 2 3 4 5 6 7 8 9 0
-
-
1 2 3
-
-
-
1 2 3 4 5 6 7 8 9 0
-
1 2 3 4 5 6 7 8 9 0


In Case 3... I got these results :

4 5 6 7 8 9 0
4 5 6 7 8 9 0
-
1 2 3 4 5 6 7 8 9 0
-
8 9 0
-
1 2 3 4 5 6 7 8 9 0
-
-
7 8 9 0
-
1 2 3 4 5 6 7
1 2 3 4
1 2 3 4 5 6
-
1 2 3 4 5 6 7 8 9 0
-
1
1 2 3 4 5 6 7 8 9


Well...I did find a solution as per Case 1 !
And I am quite happy of this ! :)

And I did find a pattern in the abnormal Cases 2 and 3 !
 
Last edited: