• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] GetRandomReal not random ?

Status
Not open for further replies.

Ardenian

A

Ardenian

I use a function in my map that requires a local real r to be set to GetRandomReal( 0.00, 100.00):

JASS:
set r = GetRandomReal( 0.00, 100.00)

It is supposed to run multiple times. However, it did not work appropriate.

After hours of debugging and desperatly beating my head against the walls I debugged r and noticed: It is not random!

Every game, the 'random' values are exactly the same!
Is this a known issue ? It is absolutly impossible the reason for this lies elsewhere. How can I workaround this ?

The function is written in a converted GUI trigger, not the map header.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,287
After hours of debugging and desperatly beating my head against the walls I debugged r and noticed: It is not random!
Well obviously. It is caused "pseudo random number generation" for a reason. They have very low statistical correlation but they are still not truly random since knowing the previous state of the system you can predict the future state (not something possible with truly random numbers as they have no relation to past state values).

Every game, the 'random' values are exactly the same!
Only if the seed is the same. This is different every time a game starts. Exception is when testing from the editor where you can use "fixed seed" for testing purposes.

Is this a known issue ?
Nope because there is no such issue.

It is absolutly impossible the reason for this lies elsewhere.
Same seed between sessions. Chance of this happening in multiplayer is practically impossible and even then the slightest change in game state (eg an attack at a different time) will cause the seed to deviate.

How can I workaround this ?
Nothing to work around. You can turn off fixed seed when testing from the editor preferences which will give you random results closer to what you will experience multiplayer or playing custom game.

As far as you should be concerned the random integers and reals are random between sessions.
 

Ardenian

A

Ardenian

Ahhh, I understand, thank you! I wasn't aware of that setting.
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
Problem is there is no way to seed it, because there is no other output of random data than RandomInt/Real, unless you start looking at nondeterministic data like unit's position or stuff like that, but that obviously cant happen at the beginning of the map
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
you can, but you have to modify the function, so basically write your own CinematicMode function(removing the seeding to 0).

Likewise you could get random int before cine starts and then seed it after the cine starts with that random number, random again
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
well as I said, there is a way to get completly random data from the game, but not at the beginning.

But you can use something like sumation of X coordinates of positions of all units belonging to some player, if your game allows unit movement that is, you get random data that should be random enough from one session to another, but as I said the drawback is you have to wait certain time to get such data. Also idiot-proofnes for cases when units dont move for instance need to be accounted for.
 
Status
Not open for further replies.
Top