Math.random to generate negative numbers


#1

Can I generate negative numbers using Math.random? If yes, how can I do this?


#2

here it is

var r = Math.random() - 1

or

var r = -Math.random()


#3

But be aware of the peculiarities in its _float_ing numbers, !!!
For instance
https://stackoverflow.com/questions/14578984/javascript-negative-float-number-calculation


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.