Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Generate Random Doubles

Started by Runicode Mar 28, 2011 at 12:35 AM 0 replies 950+ views
Original Post
Runicode
Runicode
What would be the best way to generate random doubles in the range of -4.6 to 37.5? Should I use Random or the Math class?

Thanks,
Runicode
EricTheRed
EricTheRed
Either class will work, but Random will let you choose a seed to give reproducible results. To convert a random number in the range [0.0, 1.0] to [a, b] use this formula: random * (b - a) + a. In your case this would be something like Math.random() * (37.5 - (-4.6)) + (-4.6).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.