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()
.
The seed is the initial value of the internal state of the pseudorandom number generator which is maintained by method next(int) . The invocation new Random(seed) is equivalent to: Random rnd = new Random(); rnd. setSeed(seed);
In Java Edition, the player can enter the command /seed to view the world's seed. This command is available in singleplayer worlds even if cheats are off. The player can also select 'Re-create' in the Worlds menu to see the seed.
In Golang, the rand. Seed() function is used to set a seed value to generate pseudo-random numbers. If the same seed value is used in every execution, then the same set of pseudo-random numbers is generated. In order to get a different set of pseudo-random numbers, we need to update the seed value.
When you use statistical software to generate random numbers, you usually have an option to specify a random number seed. A seed is a positive integer that initializes a random-number generator (technically, a pseudorandom-number generator). A seed enables you to create reproducible streams of random numbers.
A much more simple way of getting a seed is to generate one and store that as the seed. I am using this method for a game and want to give the player the option to generate the exact same world if he wishes too. So first I create a Random object without a seed then let that one generate a random number and use that in another random object as the seed. Whenever the player want the seed of the level I have it stored somewhere. By default the game is still random.
Random rand = new Random(); //Store a random seed long seed = rand.nextLong(); //Set the Random object seed rand.setSeed(seed); //do random stuff... //Wonder what the seed is to reproduce something? System.out.println(seed);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With