HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

GetRandomInt(a,b) - How this fella works?

01-19-2008, 03:28 PM#1
zen87
I've been wondering, how does GetRandomInt works, internally? It seems that I've been getting the same int for some random creep spawn in my map, they always spawn the same creep so I aimed my arrow at this function

is the number generated really that random?
01-19-2008, 03:30 PM#2
Rising_Dusk
Make sure you have File > Preferences > Test Map > Fixed Random Seed disabled. It really does return a random number in a real game though, but I'm not the one to explain its inner machinations.
01-19-2008, 03:41 PM#3
Alevice
Quote:
Originally Posted by zen87
is the number generated really that random?

In its practical use, yes. In reality, not at all.

Most random functions are pretty just a Pseudorandom number generator
01-19-2008, 05:17 PM#4
Captain Griffen
It uses a seed to choose a pre-created list of integers which it runs through in order, using modulus to get it in the required range.
01-19-2008, 06:56 PM#5
PipeDream
Using modulus is a terrible waste of entropy (throws away bits) and non uniform if things don't divide nicely (e.g. 0,1,2 mod 2 = 0,1,0 0 twice as likely). But mod is in fact probably how they do it.
01-20-2008, 02:57 AM#6
zen87
Quote:
Originally Posted by Rising_Dusk
Make sure you have File > Preferences > Test Map > Fixed Random Seed disabled. It really does return a random number in a real game though, but I'm not the one to explain its inner machinations.
yeah i've disabled that, I always get a same set of random number during game initialization... odd...
01-20-2008, 10:26 AM#7
Vexorian
It could just be a bug in your code, you know.

Or it could be that you are generating those units during cinematic mode.
01-20-2008, 10:29 AM#8
zen87
O_o generating units in cinematic mode can cause problem?
01-20-2008, 10:33 AM#9
Vexorian
Using randomInt in cinematic mode is likely to act like a test map with fixed seed since cinematic mode changes the seed.
01-20-2008, 12:30 PM#10
Toadcop
Collapse JASS:
        // Use a fixed random seed, so that cinematics play consistently.
        call SetRandomSeed(0)

imho anything what !=0 will gen random values. (everytime)
01-20-2008, 12:40 PM#11
cohadar
Quote:
Originally Posted by Toadcop
Collapse JASS:
        // Use a fixed random seed, so that cinematics play consistently.
        call SetRandomSeed(0)

imho anything what !=0 will gen random values. (everytime)
Even zero seed will generate random values.

File > Preferences > Test Map > Fixed Random Seed - false
only means that seed will be given value of a current clock timer every time game starts so seed will be different every time = numbers will be different every time.
01-20-2008, 12:47 PM#12
zen87
Quote:
Originally Posted by Toadcop
Collapse JASS:
        // Use a fixed random seed, so that cinematics play consistently.
        call SetRandomSeed(0)

imho anything what !=0 will gen random values. (everytime)

oh f**k, guess i should have the cinematic mode of my own then... damn randomseed...
01-20-2008, 01:12 PM#13
Vexorian
you could just choose the random values before the cinematic mode...