| 12-26-2002, 04:37 PM | #1 |
I have the following trigger: If((Random integer number between 1 and 3) less than 3) than do (Game - Set the time of day to 10.00) else do (Game - Set the time of day to 22.00) As far as I understand things, this should give me a 2/3 chance of having game time be day (10.00) and a 1/3 chance of having game time be night (22.00). Yet the reverse happens. It seemed to me like I was getting far more night runs than days runs, so I tested: in 15 tests on WC3, playing a normal SP custom game, I somehow got 10 night runs and 5 day runs. Am I doing something wrong? I find it hard to believe I'm simply unlucky: the odds of getting a flip like this by chance alone are pretty low. Can anyone see any flaw in my logic or in the trigger? |
| 12-26-2002, 04:48 PM | #2 |
Sigh, I changed it to ((Random integer number between 1 and 100) less than 67) and it seems to work perfectly. I'd still love to know what was going on above though, if anybody else has the answer, or has had a similar problem. |
| 12-26-2002, 05:03 PM | #3 |
Simple. It's BETWEEN 1 and 3, not 1 to 3. |
| 12-26-2002, 05:41 PM | #4 |
Guest | wrong |
| 12-26-2002, 07:02 PM | #5 |
Yeah, the "between" part isn't the issue. Clearly 3 is being picked, or I'd never get a nighttime scene. The issue is the *frequency* at which it's being picked. It's like I flipped a coin and got 3/4 heads, or discovered that rolling two dice gave me lots of 9's instead of lots of 7's. It's *random* in the sense that it's unpredictable, but it's weird random. |
| 12-26-2002, 07:32 PM | #6 |
Well, because I'm a glutton for punishment, I ran 30 more tests of the trigger. It's at initialization, so I reloaded the map 15 times, quit, restarted, and repeated another 15 times (in case somehow the seed was related to something at startup of WC3). Almost perfect 2:1 ratio of day:night, indicating it works perfectly. Decided to double check with a different trigger which I could execute more rapidly. Ran that another 30 times straight. Again, almost perfect 2:1 ratio. I'm going to have to conclude that the weird 1:2 ratio in the first run of 15 was just a fluke. An *unlikely* fluke to be sure (the p value's GOT to be low for something like that), but still a fluke. The randomness seems to be working fine now. I would have thought 15 tests would have been enough for things to have started balancing out, but clearly I was wrong. Sorry to waste everyone's time. |
| 01-28-2003, 09:05 PM | #7 |
I ran across this thread searching for something else, and your "problem" with generating a random number between 1 and 3 could most certainly be applicable. In the case of limiting your random number to be between 1 and 3, your degrees of freedom is only 2 (number of possible outcomes - 1). Certainly when testing the probability of a certain number being picked, the lower your degrees of freedom, the more tests you need to run in order to get a more accurate sampling. Even with that said, in any random number generator, the extreme boundaries have a very low probability of being picked, with 1 having the lowest probability. In essence, you are really expecting the 2 or the 3 to be picked the most, which actually is the reverse of what you would expect in what you are trying to accomplish. Increase the number of tests in that scenario to 75, and you would most likely be surprised by the results. |
| 01-28-2003, 09:40 PM | #8 |
I seemed to experience something similar with a recent map of mine that would select 1 of 3 'event' lists a few seconds after initialization. More often than not, it seemed to pick 3 as the list. |
| 01-28-2003, 10:10 PM | #9 |
That is because the upper bounds has a higher probability of being picked than the lower bounds. The fact that your degrees of freedom is so small only increases the probability of a number being picked in the upper bounds (the 3). Setting your degrees of freedom to 99 (1 through 100) will significantly decrease the probability of a number being selected in the extreme upper and lower bounds, thus giving you the expected results with fewer tests. In the case of choosing a specific action to take based on a 1, 2, or 3, consider choosing a random number between 1 and 99, and checking if the number is in the range 1 - 33 (#1), 34 - 66 (#2), and 67 - 99 (#3).. |
