Random number between two numbers (JavaScript)

Here’s my little function to return a random number between two numbers:

The ‘allowZero’ flag does just that.. though if you use this function you may wish to change what it does if it does generate a zero.

It’ll work on negative to positive numbers, but if you want decimal numbers (i.e. 0.0 to 1.0) you would need to do between 1 and 10, and then divide by 10 to get your result.

Leave a Reply

Your email address will not be published.