A Flash Developer Resource Site

# Thread: use of random command

1. hello, can anyone help me.
I need five movie clips to race each other.
This is the random part of the script I am
currently using:

tellTarget ("_root.run") {
m1go = random (8)+2;
m2go = random (8)+2;
m3go = random (8)+2;
m4go = random (8)+2;
m5go = random (8)+2;
}

I need each variable m""go to have a different
value. At the moment that is down to chance.
Can I do this. Also can I make the values differ
by fractions rather than whole numbers i.e. 2.5, 1.5, 3?

Your help will be very, very much appreciated

thanks

Dogmatix

2. That should work... what kind of trouble are you having? To get a fraction you could do this:

rand = random(100)/10;

that will give you a number between 0 and 99 and move the decimal over one place so that you have a number between 0 and 9.9 ...
good luck.
-E

3. Flash 5 gives you a method on the Math object:

Math.random()

That will return a value between 0.0 and 1.0

You might want to use this instead and multiply up the result until it's near the range that you require.

Regards

Andy

#### Posting Permissions

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

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap

Click Here to Expand Forum to Full Width