How do I get the seed from a Random in Java?

后端 未结 7 1476
北荒
北荒 2020-12-03 09:46

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,

7条回答
  •  北荒
    北荒 (楼主)
    2020-12-03 10:33

    The reason I'm here is that I need to remember the seed in case I need to recreate what happened in a particular program run. The code I used is:

    long seed = random.nextLong();
    random.setSeed(seed);
    

    Although this isn't quite what is asked for, I think it is probably what is required.

提交回复
热议问题