I am creating a deep clone for some object. The object contains a Random.
Is it good practice to retrieve the seed from the Random? If so, how? There isn’t a Random.getSeed().
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A Random is intended to be random. Usually you want two Random to produce different numbers rather than to produce the same numbers.
You can copy a Random using serialisation/de-serialisation and get the “seed” field using reflection. (But I doubt you should be doing either)
Unless the sequence is critical to you, you can take the view that the clone of a Random is itself or any
new Random()