Is there a way to create a only instance in a class?
At this moment, I’m trying to create only one instance of Random class. Several times I need use it with a certain seed. Is possible to change the seed later?
I’m not sure, I guess to do this is a singleton.
UPDATE: What I need is to have a only one instance of Random class. The idea is to use several times the same seed. But later I need to change the seed, so I’m not sure if the singleton is the best way because I guess change the seed means create a new instance.
In the case you’re describing, a singleton is overkill. I generally advise against singletons in any case due to the difficulty in unit testing them.
Since you specified that you’ll need to be able to periodically reseed, you’ll have to leave off the
readonlykeyword.Ex: