A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Random Numers

  1. #1
    Junior Member
    Join Date
    Jun 2002
    Posts
    18

    Random Numers

    I am trying to generate random no. For eg., between 18 and 20 with an interval of 0.5

    I understand that if I use Math.random() the interval is 0.1 and if I use Math.round, ceil or floor I will have the interval as 1. Can anyone help me generate with an interval other than 0.1 or 1

    Thanks in advance.

  2. #2
    Senior Member vevmesteren's Avatar
    Join Date
    Sep 2001
    Location
    Montréal, Québec
    Posts
    566
    random(5);

    creates a random value between 0 and 5 (0,1,2,3,4)

    check out the MX documentation on random()
    it is your mind that decides - it is with your mind that you fly


    vevmedia

  3. #3
    Junior Member
    Join Date
    Jun 2002
    Posts
    18
    ------------------------------------------------------------
    random

    Availability

    Flash Player 4. This function is deprecated in Flash 5; use of the Math.random method is recommended.

    -----------------------------------------------------------------

    I am using Flash MX. So not of any use.

  4. #4
    Junior Member
    Join Date
    Jun 2002
    Posts
    18
    Got it! (with help from Macromedia forum). Here is the solution FYI:

    [Math.floor(Math.random()*no.of intervals)]*interval+min. number

    If its between 18 and 20 with 0.5 interval then it would be:

    [Math.floor(Math.random()*5)]*0.5+18


    Hope this helps someone else too!

    Random numbers; interval; Math.random()

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center