# [vet-mm] Actionscript 3.0 Randomise

Kevork Krozian Kroset at novell1.fhc.vic.edu.au
Wed Dec 3 14:41:44 EST 2008

```Hi Travis,

"  Like random(), Math.random() is used to produce random numbers, however it functions slightly differently. Instead of providing a whole number between 0 and up to but not including the number you pass into random(), Math.random() instead returns a random decimal value between 0 and 1 without any need to pass it any value. If you want to have Math.random behave like random, you need to use the following command where n is the number you would have passed into a call to random();
Math.floor(Math.random()*n); // = random(n)

So , Math.floor cuts off any decimal value returned and just preserves the whole number part. And Math.random() returns a value between 0 and 1. When multiplied by n eg. 25 and value returned is 0 to 1 times 25 = 0 to 25 ( no decimal part achieved by Math.floor ).

So replace the gotoAndPlay(random(25)); by

gotoAndPlay( Math.floor(Math.random()*25));

Good luck

Kevork Krozian
IT Manager , Forest Hill College
k.krozian at fhc.vic.edu.au
http://www.fhc.vic.edu.au
Mobile: 0419 356 034

>>> "Travis Parker" <tparker at sjrc.melb.catholic.edu.au> 3/12/2008 1:58 pm >>>
Guys,

Am currently writing the course for next year's Cert III students. As we
did Actionscript 3.0 this year, I would like to continue with it so as to
not disrupt the students' preparation. I am trying to make a flash
document with a button for interactivity that takes them to a random frame
pre-determined frames).

Here is the code I used to jump between frames (Used for a multi-choice
game):

gotoAndPlay("Question");
}

Here is what I have for actionscript 2.0 to jump to random frames:

on (release) {
gotoAndPlay(random ( 25 ));
}

I realise that there is no randomise function in Actionscript 3.0.

Is there anyone out there with a solution to this or should I just not try
it?!?!?

Many thanks and happy holidays

Trav

--
This e-mail and any attachments may be confidential. If you are not the
addressee indicated in this message (or responsible for delivery of the
message to such person), you may not copy or deliver this message to anyone,
and you should destroy this message and kindly notify the sender by reply e-
mail. St John's Regional College does not represent or warrant that the
attached files are free from computer viruses or other defects. The attached
files are provided, and may only be used, on the basis that the user assumes
all responsibility for any loss, damage or consequence resulting directly or
indirectly from the use of the attached files, whether caused by the
negligence of the sender or not. The liability of St John's Regional College
is limited in any event to either the resupply of the attached files or the
cost of having the attached files resupplied. Any representations or opinions
expressed in this e-mail are those of the individual sender, and not
necessarily those of St John's Regional College.
_______________________________________________
http://www.edulists.com.au - FAQ, resources, subscribe, unsubscribe
VET Multimedia Mailing List kindly supported by
http://www.vcaa.vic.edu.au/vet/programs/multimedia/multimedia.html - Victorian Curriculum and Assessment Authority and
http://www.pixeled.org.au  - PixelEd Multimedia Teachers Association

```