Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Random Number Generation  RSS feed

 
Kolina Miouri
Greenhorn
Posts: 7
Java Java ME Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I am reading Deitel book on Java
package java.util.Random
In chapter 6.9 it says that :
"" The calculation that produces the pseudorandom numbers uses the time of day as a seed value to change the sequence's starting point. Each new Random object seeds itself with a value based on the computer system's clock at the time the object is created, enabling each execution of a program to produce a different sequence of random numbers ""

according to this highlighted text , when an object is created , it produces the same random number for each clall to its methods . Is this true ??? Thanks
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could always try it out!

But no, that's not what it means. The seed initialised the sequence of numbers. Each call to the same object retrieves the next in the sequence, so each call returns a different number. But two random number generators initialised with the same seed (more likely if you supply the seed explicity) will produce exactly the same sequence.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!