Closed CrystalWindSnake closed 4 years ago
Two possible approaches in my opinion:
RandChoice(IEnumerable options)
and RandChoice(IRandom random, IEnumerable options)
as part of Simulation
rather than in an extension methodOption 1 would break existing applications though as they would have to change from sim.RandUniform(a, b)
to sim.Random.RandUniform(a, b)
.
If you want to make a PR for option 2?
Thank you for your reply.
For option 1, I feel that break existing applications is not good. For option 2, all Rand* methods must be provided by the library, users cannot implement their own extensions,may need a bit more scalability in Rand methods
option 2 looks better. Is there any other better option?
@CrystalWindSnake there is always the option of subclassing Simulation and providing the Rand* extensions as part of the instance. Anyone can use such a subclass in their applications.
Another option would be to leave the methods in Simulation and implement them in IRandom as well whereas Rand* methods in Simulation then only forward the call to the protected IRandom instance. Then anyone could add methods to IRandom, still they'd need to define their own source of randomness and not use the default RNG of the Simulation class.
Is it possible to consider setting the attribute Random in the Simulation object to be public?
I try to add an extension method for object Simulation to implement the choics method like python.numpy.random.choice ,
But I found that the attribute Random cannot be obtained from the object Simulation
so sad