This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Math.random VS random.nextDouble

 
Ronnie Phelps
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic