Random (Triggers)

Started by Odb718, September 23, 2015, 06:26:49 AM

Previous topic - Next topic

Odb718

Returns a random number between 0 and 999, inclusive.

Format:
    Random
Arguments:
    none
Return type:
    int
Error conditions:
    none

Example:
trigger1 = Random <= 249
  Triggers if the random number returned is less than or equal to
  249. (This occurs with 25% probability.)


vVv Gouken718 vVv SabreTooth718 vVv


Cyanide

Random also generates a new number every single time you call it.

[State -2]
type = displaytoclipboard
trigger1 = gametime%10 = 0
params = random, random, random
text = "%d %d %d"

Will display 3 different values every 10 ticks with debug mode on (this is technically useless, but proves the point nicely)


In M.U.G.E.N there is no magic button

They say a little knowledge is a dangerous thing, but it's not one half so bad as a lot of ignorance.

XGargoyle

Quote from: Cyanide on September 23, 2015, 08:14:33 AM
Random also generates a new number every single time you call it.

[State -2]
type = displaytoclipboard
trigger1 = gametime%10 = 0
params = random, random, random
text = "%d %d %d"

Will display 3 different values every 10 ticks with debug mode on (this is technically useless, but proves the point nicely)

This is really important when making AI. There are literally tons of characters with horrible AI coding.

Adding multiple "random" triggers to cover different tier AI levels such as random<300 and random=[300,500] in the same state is useless and prone to error as both conditions can be true at the same time.


XGargoyle: Battle posing since 1979
http://xgargoyle.mgbr.net
http://www.pandorabots.com/pandora/talk?botid=e71c0d43fe35093a  <-- Please click that link
http://paypal.me/XGargoyle  <-- Donations welcome!

Felkazz

Quote from: XGargoyle on September 23, 2015, 09:01:26 AM
Quote from: Cyanide on September 23, 2015, 08:14:33 AM
Random also generates a new number every single time you call it.

[State -2]
type = displaytoclipboard
trigger1 = gametime%10 = 0
params = random, random, random
text = "%d %d %d"

Will display 3 different values every 10 ticks with debug mode on (this is technically useless, but proves the point nicely)

This is really important when making AI. There are literally tons of characters with horrible AI coding.

Adding multiple "random" triggers to cover different tier AI levels such as random<300 and random=[300,500] in the same state is useless and prone to error as both conditions can be true at the same time.

I used to make that mistake when coding the AI, now, I use a variable to store the random value and use it for the probabilities, this way, the random trigger is called only once and works way better ^^

Ricepigeon

#4
I recall reading somewhere that the random trigger is slightly bugged in WinMugen, in that it tends to call lower value numbers much more frequently than higher values (I'd imagine something to do with the initial seed). Can anyone clarify/verify this?

Iirc, it was @[user id=6464]Cyanide[/user]: who posted it initially, so tagging him (unless I'm mistaken, in which case, my apologies)

Алексей

Quote from: Ricepigeon on April 19, 2016, 07:51:55 PM
I recall reading somewhere that the random trigger is slightly bugged in WinMugen, in that it tends to call lower value numbers much more frequently than higher values (I'd imagine something to do with the initial seed). Can anyone clarify/verify this?

Iirc, it was @[user id=6464]Cyanide[/user]: who posted it initially, so tagging him (unless I'm mistaken, in which case, my apologies)

I recall reading the same thing a while back. I don't have the source, but I can back you on the recollection at the very least.

-[Все слова это только слова.]-

MarioManX1983

#6
Another fun trick you can do with this trigger is (Random%* = *) (Replace the * with a number. Ex. Random%60 = 15)

Translated into human, it means, generate a random number between 0 and 60 and when the number is 15, activate the trigger.

Example of using it in a state.
[State 1000, Ear Twitch]
type = ChangeAnim
trigger1 = Random%60 = 15
value = 2
;elem = 1
ignorehitpause = 1
persistent = 1

Another example is to use [*,*] instead of a single number. This would mean, generate a random number between 0 and 60 and when the number is any number between * and *, activate the trigger.

Example.
[State 1000, Ear Twitch]
type = ChangeAnim
trigger1 = Random%60 = [0,15]
value = 2
;elem = 1
ignorehitpause = 1
persistent = 1

In this example, the trigger will have around a 25% chance of activating every second. (60 ticks equals 1 second. 15 is 1/4th or 25% of 60. So, every second the trigger will have a 25% chance of activating.)
May you always win every round, both in MUGEN and Life. :)