Quick random question

i think I’ve got a hang on the random thing, although I’ve used random before in ie qbasic…

i think random(); gives a number between 0 and 1, and random(10); gives a number between 0 and 10, but what if i want a number between say 10 and 30?


of course… (stupid me)

Thanks ilyas… :slight_smile:

I just found out why my randoms almost never worked… I’ve been using Math.random() instead of just random()…

They’re not the same, as you said, as they don’t return the same thing. Actually, it is better to use Math.random since random has been deprecated with Flash MX… which forces you to do things like


to get a number between 0 and 100.

pom :asian:

I saw this on the Macromedia website:

onClipEvent (enterFrame) {
	Math.randomBetween = function(a, b) {
		return (a+Math.floor(Math.random()*(b-a+1)));
	num = Math.randomBetween(5, 10); // use the function

If you define Math.randomBetween as a function once, you can use it again in your movie just like

myrandomNumber = Math.randomBetween(4, 100);

?? No need the define the function onEnterFrame, is there??

No, that was for something else - No. it shouldn’t be in enterFrame - can put it in (load).

I don’t like the look of the CODE tag - I prefer the blue I was using…