YesNoOk
avatar

VarRandom (SCTRLs) (Read 5411 times)

Started by Odb718, September 22, 2015, 03:54:53 AM
Share this topic:
VarRandom (SCTRLs)
New #1  September 22, 2015, 03:54:53 AM
  • *****
  • Shame on you!
    • USA
Sets the specified int variable to a random value. Float variables cannot be set by this controller.

Required parameters:
    v = var_no (int)
        var_no is the index of the int variable to affect. It must evaluate to an integer between 0 and 59.

Optional parameters:
    range = least_val, greatest_val (int)
        least_val and greatest_val specify the least and greatest values which can be assigned by this controller, respectively. The value assigned to the variable will be a randomly chosen integer from this range. range defaults to 0,1000. If only one argument is specified, that is considered to specify the range 0,(argument).

Note 1:
    If you have placed P2 in a custom state through a successful hit, do not use variable assignment within the custom states. Otherwise, you will overwrite P2's variables, which can cause unintended malfunction of the opponent player.
Note 2:
    The example below isn't the best option out there. Refer to Cyanide's post below for a few more options.

Example:
Code:
;Assign a random number between 0 and 500 to var(5).
type = VarRandom
v = 5
range = 500

Related SCTRL:
VarAdd (SCTRLs)
VarRangeSet (SCTRLs)
VarSet (SCTRLs)

Related Triggers:
Var and FVar (Triggers)
SysVar (Triggers)
SysFVar (Triggers)
StageVar(*,***) (Triggers)

Related CNS:
IntPersistIndex & FloatPersistIndex  -  Player Variables (CNS)
vVv Mauru Mauru Released vVv
Last Edit: December 10, 2015, 02:30:28 PM by Odb718
Re: VarRandom (SCTRLs)
#2  September 22, 2015, 07:52:45 AM
  • ****
  • play more SNK games
  • I FUCKING LOVE PLATINUM!
    • South Africa
    • www.trinitymugen.net/
I don't think varrandom works with float variables :/
Re: VarRandom (SCTRLs)
#3  September 22, 2015, 09:32:05 AM
  • ******
  • Legendary XIII
  • I am the eye of the storm to come!
    • New Zealand
    • network.mugenguild.com/cyanide/
Varrandom indeed does not work with float values. It is also not the best way of randomising your variable. Since the year dot varrandom has generally picked the lower range. For example if doing varrandom of values between 0 and 10 you would get 0-4 FAR more often than you get any of the higher values. VarRandom can be replicated with the following which actually gives the correct range.

Rather than

Code:
Type = Varrandom
trigger1 = time = 0
v = 5
range = 500

you do
Code:
type = varset
trigger1 = time = 0
var(5) = random%500

To do varrandom with floats

fvar(0) = 0.001*random

This will grant values between 0.000 and 0.999. If you wish to take it further into the decimals (this will look ugly)
fvar(0) = (0.001*random)+(0.000001*random)
That will give you values between 0 and 0.999999

 If you want to randomise the first integer

fvar(0) = (2+random%6)+(0.001*random)
Giving you values between 2.000 and 8.999

I dunno if anyone has found a better method than this? It would be nice if there was something.


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.
Re: VarRandom (SCTRLs)
#4  September 22, 2015, 05:41:23 PM
  • *****
  • Gaps? Where we're going, we don't need gaps...
    • USA
    • ricepigeon.neocities.org
Building on what Cyanide was saying about VarRandom not working properly, if you wanted to set a random value within a specific range;

Code:
type = VarSet
trigger1 = time = 0
var(0) = X+floor(Z*random/1000.0)

Where, X and Y are the lowest and highest inclusive values of your range, respectively, and Z is equal to (Y-X)+1. This should give you a relatively even spread of values.
Re: VarRandom (SCTRLs)
#5  September 23, 2015, 06:24:36 AM
  • *****
  • Shame on you!
    • USA
Ricepigeon, using your method if the values were to be 54 thru 712, we'd want to set it up like
    var(0) = 54+floor(659*random/1000.0)
because   712-54+1=659

This would work because the smallest value would be
54+0, and the highest value would be 659*999=658341 -> 658341/1000=658.341 which "floors" to 658. Being 54+658=712

Note: The value 999 comes from Random; Being it's max value.
vVv Mauru Mauru Released vVv
Last Edit: September 23, 2015, 06:35:21 AM by Odb718
Re: VarRandom (SCTRLs)
#6  September 23, 2015, 03:38:18 PM
  • *****
  • Gaps? Where we're going, we don't need gaps...
    • USA
    • ricepigeon.neocities.org
Theoretically speaking, the same method could also be applied to float values, but you would end up only getting incremental values as opposed to truly randomized decimal values. You'd also have the issue of how far the decimals go, but I doubt anything past the thousandths place will make that much of a significant impact unless you're looking at some ridiculously large range of values.

Perhaps both methods combined would prove more fruitful? (ie: generating the integer and decimal values using two different calls of the Random trigger, the only problem is seeding.)
Last Edit: September 23, 2015, 03:44:31 PM by Ricepigeon
Re: VarRandom (SCTRLs)
#7  September 24, 2015, 06:34:12 PM
  • ****
  • Robotics Engineer
    • USA
    • altoiddealer@gmail.com
Good to know about the alternative to VarRandom - was using this controller for a few things, and will be replacing it.

Thanks!

Re: VarRandom (SCTRLs)
#8  September 25, 2015, 09:02:40 PM
  • ******
  • [E]
    • Mexico
for use cases, I never get tired of recomend the usae of varrandom (or cyanide's equivalent) for ais, random does  very horrible job for ai decision because of the way it stacks, and that is exactly how it should behave so no blaming mugen there. instead of having multiple random triggers in your ai's change states just use var random then check for ranges later on your code; makes for more predictable (to the coder, not the player) and stable code.

It actually shold be used in any case where random stacking makes the code complex to follow, what I mean by random staking is:

Code:
type = changestate
trigger1 = random<500
value = 1000

type = changestate
trigger1 = random>=500
value = 1010
that means that there is a 50% chance of changing to state 1000 and then a 25% chance of changing to state 1010 , because the randoms stack.

Code:
type = varset
trigger1 = 1
var(5) = random

type = changestate
trigger1 = var(5)<500
value = 1000

type = changestate
trigger1 = var(5)>=500
value = 1010

makes it easier to stack values.
Re: VarRandom (SCTRLs)
#9  October 17, 2015, 03:15:51 PM
  • avatar
  • ***
  • ̢̻̮̫̬̹̞̼̲̪̜̭͇̲͒ͪ̌ͬ̒̄̔̐͘͟ͅ ̢̋ͬ̓͗̏̇̌̑͐ͤ͗̔̊̕͏̴̣͎̟͈̬͚
    • Monaco
    type = varset
    trigger1 = time = 0
    var(5) = ;<how you write this one if range = 25,500 ;<<<< ??????????????
http://signavatar.com/32255_s.gif

please visit my request thread. here
bad grammar is art
Re: VarRandom (SCTRLs)
#10  October 17, 2015, 05:42:49 PM
  • *****
  • Shame on you!
    • USA
varset can be set to anything I believe?
But if you meant VarRandom,

[State 0, VarRandom]
type = VarRandom
trigger1 = time = 1
v = 5
range = 0,25500
;ignorehitpause =
;persistent =
vVv Mauru Mauru Released vVv
Re: VarRandom (SCTRLs)
New #11  October 18, 2015, 01:41:29 AM
  • avatar
  • ***
  • ̢̻̮̫̬̹̞̼̲̪̜̭͇̲͒ͪ̌ͬ̒̄̔̐͘͟ͅ ̢̋ͬ̓͗̏̇̌̑͐ͤ͗̔̊̕͏̴̣͎̟͈̬͚
    • Monaco
based on cyanide post in this thread
alternative of varrandom using varset
 maybe i can write it to
var(5) = (random%475)+25; is this working?
http://signavatar.com/32255_s.gif

please visit my request thread. here
bad grammar is art
Last Edit: October 18, 2015, 03:57:14 AM by yaminogun
Re: VarRandom (SCTRLs)
#12  October 18, 2015, 02:47:32 AM
  • ******
  • Legendary XIII
  • I am the eye of the storm to come!
    • New Zealand
    • network.mugenguild.com/cyanide/
This isn't a help forum really.  And the answer to your question has been posted by [E]

X+floor(Z*random/1000.0)

That's the line you're after. Why you would need to randomise values quite that high i have no idea. If you have further questions about this i'd say you should head to the help forum to find out.


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.