File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Math.random VS random.nextDouble Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Math.random VS random.nextDouble" Watch "Math.random VS random.nextDouble" New topic

Math.random VS random.nextDouble

Ronnie Phelps
Ranch Hand

Joined: Mar 12, 2001
Posts: 329
What are the advantages, if any, of using the Random class to return a random number over using the Math class?
Chad McGowan
Ranch Hand

Joined: May 10, 2001
Posts: 265
Look at the last couple of posts in this link. I tested both and found the Random class to be faster.
Daniel Searson
Ranch Hand

Joined: Dec 03, 2000
Posts: 83
From memory, I have looked at the source code for the Math class and seen that it uses a Random object to produce its values. This may be wrong in different versions of Java though.

- Daniel
It is sorta covered in the JavaRanch Style Guide.
subject: Math.random VS random.nextDouble
It's not a secret anymore!