News:

MFG's Character of the Month: October 2026 Nominations

Main Menu

Random = ?

Started by Hero, October 27, 2008, 05:12:48 PM

Previous topic - Next topic

Hero

I want to know "how work" the Random code. For example, if Im coding the AI of my Rugal:

[State -1, Slow Reppuken]
type = ChangeState
value = 1000
triggerall = var (58) >= 1
triggerall = StateType != A
trigger1 = P2MoveType = H && P2 BodyDist x <= 25 && Random = ?

What Number should be in the (?) if I want to make a probablity of 50 %??

50?
500?
0.5?

Help is aprecciated

Bastard Mami

the simple answer is 5000;

the complex answer is that it depends on what random triggers are before it.

XGargoyle

Quote from: Haruhi on October 27, 2008, 05:29:58 PM
the simple answer is 5000;

Actually, the answer is 500


------------------------------------------------------------
Random
------------------------------------------------------------

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.) 


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!

Hero

thx for help - goes to coding AI...

Fallen_angel

Quote from: Haruhi on October 27, 2008, 05:29:58 PM
the simple answer is 5000;

the complex answer is that it depends on what random triggers are before it.
Quote from: XGargoyle on October 27, 2008, 11:03:38 PM
Quote from: Haruhi on October 27, 2008, 05:29:58 PM
the simple answer is 5000;

Actually, the answer is 500



both are incorrect ......if you check his code, it wont matter wich number he pick he will  have the same probability   trigger1 = P2MoveType = H && P2 BodyDist x <= 25 && Random = ?   he will have to change the = for a > or >= or < or <=        :P

Bastard Mami


Anjel

He have "Random = insert_random_number_here" as a trigger.
Whatever number he write there it will only be 01% chance of that the random is that number (cause its only one).

Random = 1 ;01%, there is only one 1.
Random = 500 ;01%, there is only one 500.
My shitty mugen stuff:

Rajaa Retired

#7
correct therefore the trigger is Highly likely not to activate at all.

you may want to use a range of number for random. for higher yet efficient probably you may use the trigger like this

random=[0,50] meaning if it's a number equal to or between 0 and 50. (ranging from 0-999)

what [E] was talking about when he said it depends on your other randoms is(taking a guess) is if you have 2 things triggered for AI

like this

ctrl&&(random=[0,50])&&enemynear,statetype=A

ctrl&&(random=[0,50])&&enemynear,statetype=A

then, (i forget) but either the one at the top or the one at lower in the AI cmd will activate always no exception. to avoid you must be aware of what situation you have your AI reacting to and the randoms you use.


so you would have one like this

ctrl&&(random=[0,50])&&enemynear,statetype=A

and one like this

ctrl&&(random=[51,101])&&enemynear,statetype=A

that is truly how you randomize what the AI does. so be aware not only of just using randoms try and make sure they don't  overlap each other. 0 through 50 is usually good enough for good randomization.

:)

Bastard Mami

Not really, everytime you call random it is recalculated.

What I meant is that if you have a move with a 50% chance of happenning on top and next is another move with a "50%" chance, the second move will actually have a 25% chance, because it can only happen if the first one does not.

Rajaa Retired


Quote from: Haruhi on October 28, 2008, 06:20:13 PM
What I meant is that if you have a move with a 50% chance of happenning on top and next is another move with a "50%" chance, the second move will actually have a 25% chance, because it can only happen if the first one does not.

so what i said above is completely wrong?
well it seemed that way to me when i tested it out.


*goes to test again*


Bastard Mami

random is recalculated every tick, so you can have:

sctr1
ctrl&&(random=[0,500])&&enemynear,statetype=A

sctr2
ctrl&&(random=[0,500])&&enemynear,statetype=A

And both will have a "50%"  chance of happening; to make matters worse, I write it as "50%" because it's not a true 50%; while sctrl1 really does have a 50% chance, it can affect whether or not the next sctrl happens and thus decrease it's probability; this is more common in changestates.

The simplest fix is to use a var random, that way the var is calculated once per tick and you don't have to calculate relative probabilities.

Rajaa Retired

 yeah thats what i got, when i tested it before one would activate more than the other so i thought that if you use the same randoms, then one would override the other if the conditions are the same. As i tested more the other did happen but not so often. i should have tested longer last time i did it.

thanks.

Bastard Mami

You are welcome, personally I use varX = random%100 then just check for varX =[0,50] .. etc for my ai triggers.

Jesuszilla

[E]: Why not use VarRandom?

Cyanide

I imagine he's setting it as part of the trigger itself?

triggerall = var(x) := random%100

then testing off it. Probably.

Otherwise you'd have varrandom set, and read at the same value for every single attack which cuts down rather a lot on overall randomness.

Specially as varrandom in my experience tends towards the lower rather than higher numbers.


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.

Bastard Mami

Quote from: Jesuszilla on October 29, 2008, 01:14:24 AM
[E]: Why not use VarRandom?

that

Quote from: Cyanide on October 29, 2008, 01:24:17 AM
Specially as varrandom in my experience tends towards the lower rather than higher numbers.

though, for unimportant stuff like winposes I use varrandom.