A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: random variables

  1. #1
    The next Squaresoft
    Join Date
    Sep 2004
    Location
    Zanarkand
    Posts
    215

    random variables

    hiya!

    i was wondering is its possible to do random variables?

    like, if a had 2 variables, min = 10 and max = 15,

    then what i wanna do is make an event that
    randomly chooses a value between the numerical values
    of min and max, (10 - 15)

    any ideas?

    thnx a bunch!!
    "Are those gummy worms? Can I have some?"

    "Nevermind, I just saw one move by itself..."

  2. #2
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    ran=1;
    ran=math.round(math.random()*5+10);
    min=ran;

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  3. #3
    The next Squaresoft
    Join Date
    Sep 2004
    Location
    Zanarkand
    Posts
    215
    hehe, i little explaination would be appreciated.

    anyhow, tank you a bunch!
    "Are those gummy worms? Can I have some?"

    "Nevermind, I just saw one move by itself..."

  4. #4
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    The code will make a random value between 10 and 15 for the variable min

    If you want random value from the difference between min and max .........and add that to the min value......

    mini=101;
    maxi=152;
    ran_value=maxi-mini;
    ran=1;
    end_value=math.round(math.random()*ran_value+mini) ;
    trace(end_value);

    This will get you a random number between 101 and 152 for example. ( the end_value variable ).


    Note: min is a restricted word ( used by Flash for other functions ) so change as I did to mini and maxi.

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center