简体   繁体   中英

How do I obtain the state of a random number generator in c#?

I'm trying to figure out what values are causing some bad output. It's a low-probability scenario so I would like to simply log all the inputs to the generator until I find a bad seed. Unfortunately, that means recording the state of the random generator and I see no way to get at it.

Why do you need to record the state of the generator at any given point (which I don't think is possible)? As long as you record the seed, and the number of times it was called (you may need to create a class to wrap the random generator), it should be enough to reproduce the scenario, right?

You could subclass System.Random and override its methods as all of them are virtual. You could then log the results returned from each call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM