AS2 Random Number Generation Help

Rodie1952

macrumors newbie
Original poster
Nov 12, 2009
3
0
I have successfully generated random numbers using the following AS@ code:
Number1 = Math.ceil(Math.random() * 1000); This works great for generating number 1 - 1000 but only whole number. I would like to generate a number with 2 digits to the right of a decimal place i.e. 13.52. I tried some code in the Adobe help but it doesn't always work because AS2 only displays 2 digits past the decimal but there could be several more digits (i.e. display 13.52 where as the number really is 13.5346). I am working on a Flash program to drill children in math and if I could get this working it would expand the abilities of my program.
 

electric

macrumors regular
Oct 14, 2002
165
5
San Francisco, CA
This might be what you need

var Number1:Number = Math.random()*1000 ;
Number1 *= 100;
Number1 = Math.round( Number1 );
Number1 /= 100;

trace(Number1);
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.