Closed tmx7777 closed 5 months ago
I agree, this will be useful. Random
instantiation occurs in the constructors of NameGenerator, SyllableGenerator, TransformerSet, and DefaultNameTransformer which isn't a lot to overload.
There is also a static class, ListExtensions, that keeps a static Random
instance for its extension methods. I'll look at getting rid of it and reworking the extension methods so there can be more control over Random
.
New changes in upcoming version v2.3.3:
IRandomizable
System.Random
within generator classes is now accessible through the Random
property
NameGenerator
, SyllableGenerator
, SyllableSet
, and TransformSet
Random
instance during configurationI ended up skipping adding more constructor overloads, but not against it in the future if controlling seeds becomes a common activity.
v2.3.3 is now published on NuGet.org and GitHub
I propose that all classes that use
System.Random
should provide a constructor overload that allows aRandom
instance to be injected by the caller.This would allow the caller to create a random generator with a specific seed. This is helpful when creating test data that is always the same based on that seed. For example that would be the case, if one uses NUnit's random generator which is derived from
Random
and seeded individually for each test case.Alternatively it could be injected as
Func<int>
or as an interface.