2

Possible Duplicate:
Javascript/html: How to generate random number between number A and number B?

Herren und Mensch!

Ich habbe eine question for you regardings the: Randomly returning a number between a/from the range (from -> to), using the infomous Math.round()?

How is this achiveable in the controversial JavaScript scripting language supported by major number of Web-browsers?

Community
  • 1
  • 1

2 Answers2

4

That should return a random number between min and max:

function rangeRandom(min, max) {
    return min + Math.floor(Math.random() * (max - min));
}
laurent
  • 83,816
  • 72
  • 267
  • 404
4
from + Math.floor((to-from)*Math.random())

will give you a random number between from and to (not inclusive for to).

tskuzzy
  • 34,979
  • 14
  • 68
  • 136