Reputation: 13537
Will two java.security.SecureRandom
instances which are seeded with the same value initially give the same sequence of random numbers?
I am asking this because I want the same sequence of random numbers in both the client and the server. What if both of them are using the same seed value. Will the sequence be the same, or is there any way that the sequence can be made the same?
Upvotes: 3
Views: 1300
Reputation: 27286
What if both of them are using the same seed value. Will the sequence be the same?
No, they definitely won't. At least not in Oracle's Java 7 SDK implementation. See my sample code in this SO post. It appears that the implementation may elect to use additional sources of randomness, in addition to the provided seed.
Upvotes: 4
Reputation: 25676
From the API docs:
If two instances of
Random
are created with the same seed, and the same sequence of method calls is made for each, they will generate and return identical sequences of numbers.
Upvotes: 7