AS2 Random Number Generation Help

Discussion in 'Web Design and Development' started by Rodie1952, Nov 29, 2009.

  1. Rodie1952 macrumors newbie

    Joined:
    Nov 12, 2009
    #1
    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.
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    Give this a go.
    PHP:
    Number1 = (Math.ceil(Math.random() * 1000)).toFixed(2);
     
  3. electric macrumors regular

    Joined:
    Oct 14, 2002
    Location:
    San Francisco, CA
    #3
    This might be what you need

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

    trace(Number1);
     

Share This Page