Chances of something happening.

nLike

Member
Reaction score
1
I want to make a trigger that will have 4 different actions based upon probability. So i've tried something like this

Code:
Centaur
    Events
        Unit - A unit Is attacked
    Conditions
        (Attacked unit) Equal to Centaur
    Actions
        Game - Display to (All players) the text: Centaur napadnut
        Unit - Set Centaur movement speed to 500.00
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Random integer number between 1 and 100) Equal to (Random integer number between 1 and 25)
            Then - Actions
                Game - Display to (All players) the text: 0  
                Unit - Order Centaur to Move To (Random point in Centaur Area <gen>)
                Unit - Order Centaur to Orc Tauren Chieftain - War Stomp
            Else - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        (Random integer number between 1 and 100) Equal to (Random integer number between 26 and 50)
                    Then - Actions
                        Game - Display to (All players) the text: 1
                        Unit - Order Centaur to Move To (Position of (Attacking unit))
                        Unit - Order Centaur to Orc Tauren Chieftain - War Stomp
                    Else - Actions
                        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            If - Conditions
                                (Random integer number between 1 and 100) Equal to (Random integer number between 51 and 75)
                            Then - Actions
                                Game - Display to (All players) the text: 2
                                Unit - Order Centaur to Move To (Center of Centaur <gen>)
                                Unit - Order Centaur to Orc Tauren Chieftain - War Stomp
                            Else - Actions
                                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                    If - Conditions
                                        (Random integer number between 1 and 100) Equal to (Random integer number between 76 and 100)
                                    Then - Actions
                                        Game - Display to (All players) the text: 3
                                        Unit - Order Centaur to Orc Tauren Chieftain - War Stomp
                                    Else - Actions
        Unit - Set Centaur movement speed to (Default movement speed of Centaur)
        Trigger - Turn off (This trigger)
        Wait 8.00 seconds
        Trigger - Turn on (This trigger)


It's basically a trigger where based upon a chance the unit will do different stuff.

But comparing random number between 1-100 to also random number between 1-25 doesnt seem to work.
I could do this by making few triggers and then making conditions to turn on/off the triggers but I thought this was cleaner.

Does anyone have any suggestion how can this be done via one trigger?
 

MP®

Member
Reaction score
11
(Random integer number between 1 and 100) Equal to (Random integer number between 1 and 25)

This makes the chance the action is going to run at 1 % (because it first makes an integer between 1 and 100. This number has to be exactly the same as a random number between 1 and 25. Because only 1/4 of all numbers between 1 and 100 are between 1 and 25, and then it has only 1/25 chance: 0,25 * 0,04 = 0,01

I think you just want 25% of all different actions, so make a variable X = random integer number between 1 and 4 (1/4 = 0,25 = 25%)
If integer X = 1 then do action 1
If integer X = 2 then do action 2 etc for 3 & 4
 

nLike

Member
Reaction score
1
Yeah, gees I totally failed there. I've made like you said.

It works great :). Thanks friend.
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
Dont use random numbers between 1 and 4. The lower the upper bounds of the random function the less random it will be.
You should rather do a number between 1 and 1000, then divide by 334 and then check whether its 0, 1, 2 or 3.
It will give a "more" random outcome.
 

MP®

Member
Reaction score
11
Dont use random numbers between 1 and 4. The lower the upper bounds of the random function the less random it will be.
You should rather do a number between 1 and 1000, then divide by 334 and then check whether its 0, 1, 2 or 3.
It will give a "more" random outcome.

I don't think that makes any difference? chance of being 1 is as much of being 2, 3 of 4, all 25%

every time again
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
it does.
This is a computer, it doesnt know random.
It is statistically shown that small random numbers tend to be not random at all. Chances might be like 35%, 30%, 20%, 15% instead of 25% for each if you only use numbers between 1 and 4.
 

NoobImbaPro

You can change this now in User CP.
Reaction score
60
Quote:"I don't think that makes any difference? chance of being 1 is as much of being 2, 3 of 4, all 25%"
The 25% chance is if you random infinite times.
Accname's right. 1-1000/250 is more random than 1-4.
 

MP®

Member
Reaction score
11
If you run the trigger 1000 times on my way, you think the times action A runs significant more often than action D?

I would like to test it with 2 simple triggers, will run it 100.000 times and count the times it was action A, B, C and D

First trigger with random integer between 1 and 4
Second trigger with random integer between (1 and 1000)/250
 

NoobImbaPro

You can change this now in User CP.
Reaction score
60
make an algorithm and run it.
Run it 10000 times
rand = Rand(1,4)
num_1_4[rand] = num_1_4[rand] + 1

Then do that
rand = Rand(1,1000)/333+1
num_1_1000[rand] = num_1_1000[rand] + 1

then print the results in 100% scale.
 

Smitty

Member
Reaction score
20
Or, easier method, tell it to loop 1-1000 set Integer=Integer+random number between 1 and 4. Result should be near as dam it 2500. Only issue is if it happens to favour 1 AND 4 for some reason.
 

NoobImbaPro

You can change this now in User CP.
Reaction score
60
that's easier but does not solve your problem, we want to know how much % every number will be returned. If 1 2 3 4 have the same chances it means that's random, if they are unbalanced just use bigger scale.
Your's can be up 2500 or down, 2 results, mine has 4 (more accurate).
 

NotInTheFace

Member
Reaction score
17
You guys got me curious, so I ran the test (10000 random numbers using either GetRandomInt(1,4) or GetRandomInt(1,1000) / 250 + 1)

Run 1Run 2Run 3
GetRandomInt(1,4)
1257924212482
2251225192507
3250125362506
4240825242505
GetRandomInt(0,999) / 250 + 1
1249725092549
2244125212572
3253925172465
4252324532504

I'm not sure how to interpret the numbers. It looks like the 2nd method has SLIGHTLY less variance, but it's pretty tiny. I was honestly expecting something more dramatic. I'd also be interested to see how often the PRD generates "runs" and whether there's a method to minimize them.
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
@NotInTheFace:
Your table is not entirely correct. If you run a random number from 1 to 1000 and divide by 250 there are 5 possible numbers and not just 4. it goes from 0 to 4.
 

NoobImbaPro

You can change this now in User CP.
Reaction score
60
you've run it 10000 times, how the heck you gonna see a dramatic difference??
The second is a bit unbalanced so it is more random.
 

NotInTheFace

Member
Reaction score
17
Run again with 1,000,000 numbers generated:


1..40..999
1250441250218
2249153249405
3250496249403
4249910250974

I'm still not seeing a big difference. 847 off median for the first way, 974 off median for the second.

I don't think you could say that one way is "more random" than the other.

I also ran a test for runs of the same number being generated. Either method yielded very similar results.
 

MP®

Member
Reaction score
11
Looks like I was right after all :)

Its clear that there is no significant difference, but If you doubt it, I could test it statistically
 
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