<classwork>

Random

The random function can be fun and interesting. You can randomize movement of something, randomize the frame that a movie will go to, or randomize a movies that will load into your movie.

The possibilities are endless.
You simply choose the Random function in the actions panel, set a value that you want the number of options to be between.

Math.random()

Method: returns n, where 0 <= n < 1

If you don't want 0, you must add 1 to the equation to make sure that you don't get 0.
ex. Math.random(20) +1
for a number between 1 and 20

For example, lets say I have 10 audio files, each one in a separate swf movie. I can set the random function as follows.

loadMovie ("music"+ (Math.random(10) +1)+".mp3", "myMovieClip")

note: Flash 5 and below used Random(), not Math.random


The following snow file uses Random to create random numbers used to set the snowflakes position and size.

download the snowing file example shown above (file name: snowing.fla)
right click on the file (control-click for Mac) and select to download to your drive.