YesNoOk
avatar

Probability and the Random trigger (Read 154 times)

Started by felineki, January 27, 2014, 05:47:55 am
Share this topic:
Probability and the Random trigger
#1  January 27, 2014, 05:47:55 am
  • ****
I'm working on a character that involves a lot of variables that have several possible values chosen according to certain probabilities. For example, one variable I want to be -3, -2, -1, 0, 1, 2, or 3 with respective probabilities of 1/32, 4/32, 5/32, 12/32, 5/32, 4/32, and 1/32.

Upon the assumption that the Random trigger was simply being calculated once each tick, I had been coding it like this:
Code:
[State -2, 4]
type = Null
trigger1 = Random % 32 = 0
trigger1 = var(23) := -3
trigger2 = Random % 32 = [1, 4]
trigger2 = var(23) := -2
trigger3 = Random % 32 = [5, 9]
trigger3 = var(23) := -1
trigger4 = Random % 32 = [10, 21]
trigger4 = var(23) := 0
trigger5 = Random % 32 = [22, 26]
trigger5 = var(23) := 1
trigger6 = Random % 32 = [27, 30]
trigger6 = var(23) := 2
trigger7 = Random % 32 = 31
trigger7 = var(23) := 3
But then I realized that the Random trigger is probably being calculated each time it's read rather than simply once each tick. Now I'm having trouble wrapping my head around the math involved to get this sort of probability working the way I want. Any suggestions?
Re: Probability and the Random trigger
#2  January 27, 2014, 05:51:04 am
  • ******
  • I'm a fuffy.
    • USA
    • www.trinitymugen.net
The random trigger is calculated EVERY time it is called, not just one tick. So you can have a different random value for a trigger in a different SCTRL, and have a random value for another trigger for another SCTRL on that SAME tick, but both random values will be different (wow what a clusterfuck that sentence is). If you want the random to be universal, use VarRandom.

In addition, the random trigger is not truly random. I recall @Vans running into issues with this when he was making Shingo's AI. For instance, random%40 = 1 should be pretty unlikely, right? Well, turns out it's more likely than you think.
Last Edit: January 27, 2014, 05:55:23 am by Jesuszilla
Re: Probability and the Random trigger
#3  January 27, 2014, 06:22:38 am
  • ****
I see, thanks. I think I'll go ahead and use a variable and VarRandom then.

Nice to see you back, BTW.