in your code, there is a random algorithm, Math.floor(Math.random() \* (max -min )) +1; this can't produce correctly random number [a, b]. there is a correctly method, Math.floor(Math.random() \* (max -min + 1)) + min;