Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get the current seed of Random in C#?

Tags:

c#

random

In my game I'm going to use random values to pick the reward the player gets from a chest. The problem is that you can quick save and quick load and that means they can keep reloading to re-randomize until they get what they want. Is there some way that I could get the current seed value of my Random object and possibly return to that same point when they load so that they couldn't abuse the randomization?

like image 921
Ted Avatar asked May 13 '11 00:05

Ted


People also ask

What is random seed in C?

General description. srand() uses its argument seed as a seed for a new sequence of pseudo-random numbers to be returned by subsequent calls to rand(). If srand() is not called, the rand() seed is set as if srand(1) was called at program start. Any other value for seed sets the generator to a different starting point.

What is the rand () 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.

What is seed in random sampling?

The seed() method is used to initialize the random number generator. The random number generator needs a number to start with (a seed value), to be able to generate a random number. By default the random number generator uses the current system time.

How do you identify a random seed?

You can mimic randomness by specifying a set of rules. For example, “take a number x, add 900 +x, then subtract 52.” In order for the process to start, you have to specify a starting number, x (the seed). Let's take the starting number 77: Add 900 + 77 = 977.


1 Answers

This is not possible.

Instead, you can serialize the Random instance using binary serialization.
Random is [Serializable], and the seed and internal state will persist.

Note, however, that saving the random seed allows your players to predict the future, which is very useful if you allow saving in battle.

Also note that users can still save, open the chest, load, perform an action that generates a random number, then get a different item from the chest.

like image 63
SLaks Avatar answered Oct 02 '22 18:10

SLaks