SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Funtion Random

  1. #1
    SitePoint Zealot XzAzX's Avatar
    Join Date
    Apr 2002
    Location
    Holland
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Funtion Random

    Ok, i've got :
    Code:
    var dmg=Math.floor(Math.random()*11)
    if(dmg == "0"){ dmg = "1"; }
    But how do I make the random var lay, lets say, between 5 and 10?
    ofcourse i can do :
    Code:
    if(dmg < 5 ){ dmg = "6"; }
    But I wan't a way to do this within the JS random function ..
    help plz?
    _o_ OOP _o_

  2. #2
    SitePoint Zealot
    Join Date
    Jul 2002
    Location
    Fort Lauderdale
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    upperBound = 10; lowerBound = 5;
    randomNum = Math.round(lowerBound + Math.random()*(upperBound - lowerBound));

    www.unpossiblemedia.com - A Fort Lauderdale based multimedia company.

  3. #3
    SitePoint Zealot XzAzX's Avatar
    Join Date
    Apr 2002
    Location
    Holland
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, this works perfect
    thx a lot m8
    _o_ OOP _o_


Bookmarks

Posting Permissions

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