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
  • 88,262
  • 77
  • 290
  • 428
4
from + Math.floor((to-from)*Math.random())

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

tskuzzy
  • 35,812
  • 14
  • 73
  • 140