A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: random() question...

  1. #1
    Senior Member
    Join Date
    Nov 2000
    Location
    Jerusalem, Isreal
    Posts
    254

    random() question...

    hi all,
    does anyone know if there's a way to create a random number between -5 and 5 (for the sake of the matter). i mean from a negetive number to a positive one.
    thx.
    Matti Bar-Zeev,
    scriptaholic.

  2. #2
    Senior Member sxdesign's Avatar
    Join Date
    Aug 2000
    Location
    Serbia
    Posts
    844
    Code:
    Math.rangedRandom = function(l,h) {
    // Copyright 2001 by Sx Design Team
    if (l>h) {
    var tmp = l;
    l=h;
    h=tmp;
    }
    return Math.round(Math.random()*(h-l))+l;
    }
    Syntax is quite easy:

    Math.rangedRandom(int,int);

    where both parameters represents 2 numbers between which you want to find a random number...

    hope it helps...

  3. #3
    Senior Member
    Join Date
    Nov 2000
    Location
    Jerusalem, Isreal
    Posts
    254

    thx!

    yeah - great script you made here, but i found the solution. i needed something more simple than that, and i think you miss understood me... nevermind, great way you worked out.
    thx again.
    Matti Bar-Zeev,
    scriptaholic.

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