Javascript : random number between variables issue

Posted by Mayhem on Stack Overflow See other posts from Stack Overflow or by Mayhem
Published on 2012-10-16T04:58:10Z Indexed on 2012/10/16 5:02 UTC
Read the original article Hit count: 160

Filed under:
|

I've seen the other examples on this site but I just can't get it to work.

I'm trying to generate a random number between 2 user input variables on a form. The numbers will always be positive numbers.

min = document.getElementById('min').value;
max = document.getElementById('max').value;
waitTimer = Math.floor(Math.random() * (max - min + 1)) + min;

When min = 5 / max = 10, waitTimer is sometimes returning results like 2, 4 and 28 and so on.

What am I doing wrong?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about random