hossein_au
Established Member
- Joined
- May 2, 2013
- Posts
- 1,711
The problem with a random number generator, is it can generate the same number more than once. Yes there's a low probability that would happen, but being random, there's no reason it cannot happen, as it doesn't know, remember or care what the last number generated was.
While this is technically correct, one can reduce the likelihood by (increasing the generated range by) using something like:
SET !VAR1 EVAL("var randomNumber=Math.floor(Math.random()*99+1); 1+randomNumber/100;") <-- this generates a random "cent" and returns a number between $1 and $2.
And can recover from an error (if indeed the same number is generated twice) by using:
SET !ERRORIGNORE YES
Of course, like any programming exercise, there are at least x+1 different ways x number of programmers can achieve the same effect!