Random number bug in the World Editor?

Ouguiya

New Member
Reaction score
11
Hello everyone!

I wanted to ask a short question about the world editor, since recently I have found a phenomenon which I find really unnerving.

You certainly all know the "Math - Random Integer / Real Number between x and y" function, in the GUI.
It's used for many things. Random game modes, random hero choosing, dynamic and unpredictable game events and so on.

The only problem: I have been asking myself lately if the randomness is truly random in Warcraft 3.

I made a quick test to see if my suspicions were correct. I made a simple, empty map, with a single trigger, which outputs a number every 2 seconds.
Writing down the number, and measuring how many times it occurs, should show if the trigger was truly random.

There were two tests: One with relatively low boundaries, and one with high ones.

First case: Random Number from 1 - 57
Measured numbers: 127
Result: The detailed result would be very long to list. suffice to say that a total of 5 numbers never occurred once, and 4 numbers occurred 5 times (even though every number should only appear around 2-3 times, statistically)

Second case: Random Number from 1-5:
Measured numbers: 77
Detailed result:
Number 1 occurred: 15 times
Number 2 occurred: 9 times
Number 3 occurred: 21 times (!)
Number 4 occurred: 18 times
Number 5 occurred: 14 times

Now I think you will agree, that this is quite off the scale. Normally, every number should have occurred around 13-17 times at most.

If one were to play a map, where there are 5 game modes, and the game mode is chosen randomly, the players will play game mode 3 more than twice as often as game mode 2.

What I wanted to ask, is if some people have also noted this "unrandomness" of the "random" function from the World editor, or if it is even a known bug.

If so, is there any way to "trick" the system so to get a good and well balanced result, a JASS function, maybe even a complex trigger designed ONLY to spit out good random numbers, since nobody likes to have a lot of possibilities, but only few options, because the random function is messed up.

Yours,

Ouguiya
 

Romek

Super Moderator
Reaction score
964
File -> Preferences -> Test Map tab -> Uncheck "Use Fixed Random Seed"
 

Rapmaster

Ultra Cool Member
Reaction score
95
I'm not really into statistics or math, but taking only 127 samples doesn't sound significant for 57 possible results. Try a few thousand!

Computers can't generate random numbers but they basically try to generate numbers that the user can't predict. Same seed means the same sequence of numbers. An easy way, unless you are doing important stuff like cryptograpghy, is to just base it off the current time or some value derived from the user's mouse movements (not saying you can do this in War3, but I'm talking general programming.) http://en.wikipedia.org/wiki/Pseudo-random_number
 

CaptainJack

New Member
Reaction score
2
This isn't a bug, this is due to microprocessors not having an actual random function. As for some numbers not showing up, that is because the results are random, thus you won't get every number every time. Again a processor only knows 0 and 1 so results that are even close to random are probably beyond most people comprehension.
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
> Normally, every number should have occurred around 13-17 times at most.

If random fails to meet your expectations, it is random indeed.
 

BarzahdX

Active Member
Reaction score
18
Make 15 tests over and over, if they all have the same numbers, it's fixed, if not, it's actually random.

One irritating thing about randomness is truly grasping it's meaning. 800 numbers, 1 - 1000.. They could all be 62, nothing about randomness says it's supposed to be even, or equal. Unfortunately, even random % work this way. -,-

Example: This is my favorite example, because it always wins. You flip a coin, it can be heads every time, but it's still 50%. ^^ Note: Not taking into account the actual coin flipper, and how one flipped the coin, such variables do not exist in my example of fact.
 

lindenkron

You can change this now in User CP
Reaction score
102
Make 15 tests over and over, if they all have the same numbers, it's fixed, if not, it's actually random.

One irritating thing about randomness is truly grasping it's meaning. 800 numbers, 1 - 1000.. They could all be 62, nothing about randomness says it's supposed to be even, or equal. Unfortunately, even random % work this way. -,-

Example: This is my favorite example, because it always wins. You flip a coin, it can be heads every time, but it's still 50%. ^^ Note: Not taking into account the actual coin flipper, and how one flipped the coin, such variables do not exist in my example of fact.

Exactly.

Theres the same % chance of each number between 1-1000 of happening .. but as I wrote .. Random .. Is random. So 999 or 1000 or what ever number, could happen 1000 times in a row. Which is what random is .. It's .. Random :D
 

Ouguiya

New Member
Reaction score
11
Unfortunatly however, I have to add, that there is also a way of calculating the chance of getting always the same number.

thing is: It COULD happen, that 1000 comes 1000 times, but in that case one should really ask himself, if the random really is random.

Normally, if the system truly is random, you should get an equal distribution. Same with the coin: It COULD happen that you always get heads, but seriously: How often does this happen? Answer: alsmost never. Because it's not very probable. Same with the 1000 a thousand times thingy: The chance for this to occur in a row would be 1 / 1000 (because the numbers go from 1-1000), and then this 1000 times, meaning: 1/(1000*1000*1000*1000*1000...), a REALLY low number.

Now to step away from all the maths (cause to be honest, I hate probability and statistics calculation. It makes my head hurt.)

To get back to realism: In theory it IS possible, that if you toss a dice, you would always get the number 6 say. But try that in a casino... If you really always get 6, I guess the casino guards would quickly circle around you, and serioulsy check the dice for manipulation ;).

The reason for this? It never happens that you always get the same numbers. It could happen, but we all know that it doesn't. For: As probable as it is you get the same number, it is (x-1)/x more probable to get the other numbers (with x beeing the amount of numbers you can get. In case of the dice, x would be 6). At least if the system truly generates a random number every time it is activated (in case of the dice: rolled).

However, I do want to thank the first two replies very much (and all the others too), who gave at least some hints as to how make the randomness better.

Yours,

Ouguiya
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
> who gave at least some hints as to how make the randomness better

Post #3 applies to "test map" only. And is an actual feature.

Post #2 helps nothing...
Seeding a random generator with itself improves nothing...


> you should get an equal distribution

Actually, you do.
Sooner or later, the generator will repeat its sequence...
However, that only happens after about 4 billion calls (on a 32 bits generator).

Other than that, it's random already.


> It never happens that you always get the same numbers.

That is what you expect. Your expectations aren't random though.
 

SFilip

Gone but not forgotten
Reaction score
634
77 times? That's way to small to mean anything.
GetRandomInt(1,5) 10000 times:
1 occurred 2000 times.
2 occurred 2026 times.
3 occurred 1972 times.
4 occurred 1990 times.
5 occurred 2012 times.
 

Strilanc

Veteran Scripter
Reaction score
42
(Replying to original post)

Your first case makes it obvious you don't do a lot of statistics. The odds of every result showing up 2 or 3 times are very, very small. It's very likely that at least one will have less than 2 or more than 3 elements. In fact it's very likely that a bunch of them will.

If you do more samples you will find that these variations contribute less and less to your totals. Try doing ten thousand samples [use code, not paper] instead of 127, and you'll find the results don't vary by +- 50% anymore.

Just don't extrapolate that into some sort of "the universe evens out" gambler's fallacy BS. The actual magnitude of the differences will increase (+-100 instead of +-3), even though the percentage variations decrease (+-1% instead of +-50%).
 

MindWorX

New Member
Reaction score
8
I know it's a late response, but if you really want to have "even random" numbers, use a stack, fill the stack with the numbers 0..n, then remove a random number from the stack, until it's empty, and refill it with numbers from 0..n, that should give you "even random".

EDIT: Also, a quick note about you thinking that it's possible to throw multiple sixes in a row, but it just doens't happen, is not true. I play dungeons and dragons once a week, and i've experienced up to 4 20's in a row on a 20sided die, more than once too, that's a 1/160000 chance.
 

Stryke

New Member
Reaction score
6
There is no way to make something truly random.
How WE probably makes random numbers is probably using a value that is always changing such as time, and selects a 'random' number by using a formula involving time.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      • Ghan
        Administrator - Servers are fun

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top