REAL Variable - How do I add Random variance?

Bird

Ultra Cool Member
Reaction score
29
Does anyone see a problem with the following Code???
Code:
Set MyReal = (Random real number between (MyReal x 1.10) and (MyReal x 0.90))
I have a Real variable, and all I am trying to accomplish is give the variable a 10% variance... as in.. if my Real was valued at 100 during my game, I run this line of code to add some random-ness to the value (make it valued somewhere between 110 and 90). But *every* time I run this line of code, the Real variable *only* increases. Never decreases.

I am very confused.
 

kaboo

New Member
Reaction score
45
are u using WE test map or normaly loading the map? cz if u use test map your "random" number will be always the same
 

Jesus4Lyf

Good Idea™
Reaction score
397
>the Real variable *only* increases
Are you sureee. Run the code multiple times. And there's a random seed option in the world editor somewhere, I forget where though. If your map uses the same random seed each time (default) then you will always get the same series of values when you execute that code (unless you have other random functions in use).
 

Bird

Ultra Cool Member
Reaction score
29
Yes I took off the Fixed Seed long ago. I have run this thousands of times. The problem is not that I am getting the *same* values. It is that they are always higher.

I triple dog dare any of you to run this code:

Code:
Actions
    Set S_INS_Real = 100.00
    Game - Display to (Player group((Triggering player))) the text: (Raw value is:  + (String(S_INS_Real)))
    Set S_INS_Real = (Random real number between (S_INS_Real x 1.10) and (S_INS_Real x 0.90))
    Game - Display to (Player group((Triggering player))) the text: (Random(10)value is:  + (String(S_INS_Real)))
    Set S_INS_Real = 100.00
    Game - Display to (Player group((Triggering player))) the text: (Raw value is:  + (String(S_INS_Real)))
    Set S_INS_Real = (Random real number between (S_INS_Real x 1.20) and (S_INS_Real x 0.80))
    Game - Display to (Player group((Triggering player))) the text: (Random(20)value is:  + (String(S_INS_Real)))

In fact, not only are they higher... they are in a much greater variance than I am asking for. I get values of 150+ on the 20% variance. How can 100 x 1.2 be any higher than 120???
 

Bird

Ultra Cool Member
Reaction score
29
Screen shows what happens when you run the code.
 

Attachments

  • WC3ScrnShot_092909_014431_01.jpg
    WC3ScrnShot_092909_014431_01.jpg
    108.9 KB · Views: 92

Bird

Ultra Cool Member
Reaction score
29
Here is the solution. This one works properly - although I see no reason why my first example does not work.

Code:
Actions
    Set S_INS_Real = 100.00
    Game - Display to (Player group((Triggering player))) the text: (Raw value is:  + (String(S_INS_Real)))
    Set S_INS_Real = (S_INS_Real x (Random real number between 0.90 and 1.10))
    Game - Display to (Player group((Triggering player))) the text: (Random(10)value is:  + (String(S_INS_Real)))
    Set S_INS_Real = 100.00
    Game - Display to (Player group((Triggering player))) the text: (Raw value is:  + (String(S_INS_Real)))
    Set S_INS_Real = (S_INS_Real x (Random real number between 0.80 and 1.20))
    Game - Display to (Player group((Triggering player))) the text: (Random(20)value is:  + (String(S_INS_Real)))
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
Here is the solution. This one works properly - although I see no reason why my first example does not work.
I imagine it's because you were setting the first number - the low limit of the range - to a higher number than the second.
 

Strilanc

Veteran Scripter
Reaction score
42
I guess it couldn't handle the upper limit first? That surprises me.

Also, if 90% to 110% is applied iteratively, you'll find your value actually decays towards 0 over time (essentially: because 0.9*1.1 = 0.99).
 

Bird

Ultra Cool Member
Reaction score
29
I imagine it's because you were setting the first number - the low limit of the range - to a higher number than the second.
Wow, interesting. I figured it was due to the format, not the order of high/low. But I just ran the test again in my 2nd format, but reversing the high/low.. and it fails just as my first example fails. Really bizarre.

This...
Code:
Set S_INS_Real = (S_INS_Real x (Random real number between 0.90 and 1.10))
does not equal this...
Code:
Set S_INS_Real = (S_INS_Real x (Random real number between 1.10 and 0.90))

Strilanc said:
Also, if 90% to 110% is applied iteratively, you'll find your value actually decays towards 0
I reset the value to 100 every time. I don't continually vary the variant.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top