aspose file tools*
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "Math.random VS random.nextDouble" Watch "Math.random VS random.nextDouble" New topic
Author

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.
http://www.javaranch.com/ubb/Forum34/HTML/001112.html
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Math.random VS random.nextDouble