Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top