Random number not so random?

Mmage

New Member
Reaction score
7
Hello, I am making a map in which units spawn in one of 3 barracks and run across a field into one of 3 enemy barracks, and when they get there, it sends them back and goes again. I use Set RandomNumber for the randomization of the return and attack path, but i have noticed a few things.

Trigger-
Code:
North Return
    Events
        Unit - A unit enters Northwest Return 1 <gen>
        Unit - A unit enters Northwest Return 2 <gen>
        Unit - A unit enters Northeast Return 1 <gen>
        Unit - A unit enters Northeast Return 2 <gen>
        Unit - A unit enters North Return <gen>
    Conditions
        (Owner of (Triggering unit)) Equal to Player 1 (Red)
    Actions
        Set RandomNumber = (Random integer number between 1 and 3)
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                RandomNumber Equal to 1
            Then - Actions
                Set ReturnLoc = (Center of South Barracks Left <gen>)
                Unit - Move (Triggering unit) instantly to ReturnLoc
                Custom script:   call RemoveLocation(udg_ReturnLoc)
                Set RandomNumber = (Random integer number between 1 and 3)
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        RandomNumber Equal to 1
                    Then - Actions
                        Set ReturnLoc = (Center of North Barracks Left <gen>)
                        Unit - Order (Triggering unit) to Attack-Move To ReturnLoc
                        Custom script:   call RemoveLocation(udg_ReturnLoc)
                    Else - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        RandomNumber Equal to 2
                    Then - Actions
                        Set ReturnLoc = (Center of North Barracks Mid <gen>)
                        Unit - Order (Triggering unit) to Attack-Move To ReturnLoc
                        Custom script:   call RemoveLocation(udg_ReturnLoc)
                    Else - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        RandomNumber Equal to 3
                    Then - Actions
                        Set ReturnLoc = (Center of North Barracks Right <gen>)
                        Unit - Order (Triggering unit) to Attack-Move To ReturnLoc
                        Custom script:   call RemoveLocation(udg_ReturnLoc)
                    Else - Actions
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                RandomNumber Equal to 2
            Then - Actions
                Set ReturnLoc = (Center of South Barracks Mid <gen>)
                Unit - Move (Triggering unit) instantly to ReturnLoc
                Custom script:   call RemoveLocation(udg_ReturnLoc)
                Set RandomNumber = (Random integer number between 1 and 3)
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        RandomNumber Equal to 1
                    Then - Actions
                        Set ReturnLoc = (Center of North Barracks Left <gen>)
                        Unit - Order (Triggering unit) to Attack-Move To ReturnLoc
                        Custom script:   call RemoveLocation(udg_ReturnLoc)
                    Else - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        RandomNumber Equal to 2
                    Then - Actions
                        Set ReturnLoc = (Center of North Barracks Mid <gen>)
                        Unit - Order (Triggering unit) to Attack-Move To ReturnLoc
                        Custom script:   call RemoveLocation(udg_ReturnLoc)
                    Else - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        RandomNumber Equal to 3
                    Then - Actions
                        Set ReturnLoc = (Center of North Barracks Right <gen>)
                        Unit - Order (Triggering unit) to Attack-Move To ReturnLoc
                        Custom script:   call RemoveLocation(udg_ReturnLoc)
                    Else - Actions
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                RandomNumber Equal to 3
            Then - Actions
                Set ReturnLoc = (Center of South Barracks Right <gen>)
                Unit - Move (Triggering unit) instantly to ReturnLoc
                Custom script:   call RemoveLocation(udg_ReturnLoc)
                Set RandomNumber = (Random integer number between 1 and 3)
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        RandomNumber Equal to 1
                    Then - Actions
                        Set ReturnLoc = (Center of North Barracks Left <gen>)
                        Unit - Order (Triggering unit) to Attack-Move To ReturnLoc
                        Custom script:   call RemoveLocation(udg_ReturnLoc)
                    Else - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        RandomNumber Equal to 2
                    Then - Actions
                        Set ReturnLoc = (Center of North Barracks Mid <gen>)
                        Unit - Order (Triggering unit) to Attack-Move To ReturnLoc
                        Custom script:   call RemoveLocation(udg_ReturnLoc)
                    Else - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        RandomNumber Equal to 3
                    Then - Actions
                        Set ReturnLoc = (Center of North Barracks Right <gen>)
                        Unit - Order (Triggering unit) to Attack-Move To ReturnLoc
                        Custom script:   call RemoveLocation(udg_ReturnLoc)
                    Else - Actions
            Else - Actions

Here are the problems.

1- South Barracks Left has the least amount of units per wave, usually 1 or 2 out of 12. Furthermore, they only go straight up to North Barracks Left, never going to North Mid or North Right.

2- South Barracks Mid has a medium amount of units per wave and they split to North Left and North Mid, but they never go to North Right.

3- South Barracks Right has the majority of units per wave and they split to each North Barracks.

There is also a South Return with the same trigger and problems, but reversed so they come from North and return at South. I would like to see the unit spawn/split evened out. Can anyone help with these problems?
 

Oninuva

You can change this now in User CP.
Reaction score
221
If you want it even out why not just make it spawn at one of them and go to the next.. Random has a "random" chance to be the same..

For example.. if I rolled a dice 10 times.. there is a slim chance I can get 6 every time.. Nobody said it's impossible.
 

Sajberhippie

New Member
Reaction score
30
If you want it even out why not just make it spawn at one of them and go to the next.. Random has a "random" chance to be the same..

For example.. if I rolled a dice 10 times.. there is a slim chance I can get 6 every time.. Nobody said it's impossible.

Yeah, a 1/60466176 chance. That isn't a big problem.
 

lindenkron

You can change this now in User CP
Reaction score
102
This reminds me of the thread where someone posted that the Math - Random was bugged because numbers weren't equally random...

He apparrently did like 1000 randoms and counted how many of each he got.. and was supprised why he didn't get even of all...

The answer:
ITS RANDOM.

That's why it is random, and called random, because it's random. If you want to minimize the chance of the same field / etc being selected twice you can avoid that by checking it. But if you only add random, it could be the same field 100 times before it changes (odds are small, but as I said.. --!Random!--)

Good luck,
-Lindenkron

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

WolfieeifloW

WEHZ Helper
Reaction score
372
I just ran my own test.
Randomed a number between one and ten 1000 times.
Results:
Ones : 102
Twos: 116
Threes: 90
Fours: 101
Fives: 93
Sixes: 100
Sevens: 90
Eights: 92
Nines: 107
Tens: 109
results1000ec2.jpg

Enjoy ;) !

EDIT: 10000 randoms:
Ones : 1035
Twos: 963
Threes: 1005
Fours: 1020
Fives: 981
Sixes: 992
Sevens: 988
Eights: 1003
Nines: 973
Tens: 1040
results10000ds5.jpg
 

Dameon

"All the power in the world resides in the eyes"
Reaction score
127
Yeah, a 1/60466176 chance. That isn't a big problem.

wow your math is way off, no matter what when you roll a die you chance of getting any number is always 1 in 6, the numbber you got before has no effect on your next number. Unless you cheat and drill another hole in the one side, then you got a 1 in 3 chance to get a 2 :D
 

tom_mai78101

The Helper Connoisseur / Ex-MineCraft Host
Staff member
Reaction score
1,703
Random, it's the basis to all life's form.

There are "42" possibilities for randomness.
 

ZeroThirteen

New Member
Reaction score
35
wow your math is way off, no matter what when you roll a die you chance of getting any number is always 1 in 6, the numbber you got before has no effect on your next number. Unless you cheat and drill another hole in the one side, then you got a 1 in 3 chance to get a 2 :D

Actually, he was right.
The chances of rolling a six are 1/6.
The chances of rolling a second six are 1/6.
Rolling 2 sixes, therefore, has a 1/36 chance.
3 sixes would be 6^3, 4 would be 6^4, 5 would be 6^5, etc.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top