diff --git a/Syllabore/Syllabore.Tests/NameGeneratorTests.cs b/Syllabore/Syllabore.Tests/NameGeneratorTests.cs index 52f275d..ee3504b 100644 --- a/Syllabore/Syllabore.Tests/NameGeneratorTests.cs +++ b/Syllabore/Syllabore.Tests/NameGeneratorTests.cs @@ -161,23 +161,27 @@ public void NameGeneration_WithSequencesOnly_Allowed() [TestMethod] - [DataRow(0)] - [DataRow(12345)] - public void NameGenerator_StaticRandomSeed_CreatesPredictableOutput(int seed) + [DataRow("aeiou", "strlmnp", 0)] + [DataRow("aeiou", "strlmnp", 12345)] + public void NameGenerator_StaticRandomSeed_CreatesPredictableOutput( + string vowels, + string consonants, + int seed + ) { - var sutSyllables = new SyllableGenerator("aeiou", "strlmnp"); - sutSyllables.Random = new Random(seed); - - var sut = new NameGenerator(); - sut.Random = new Random(seed); - sut.UsingSyllables(sutSyllables); - - var comparisonSyllables = new SyllableGenerator("aeiou", "strlmnp"); - comparisonSyllables.Random = new Random(seed); - - var comparison = new NameGenerator(); - comparison.Random = new Random(seed); - comparison.UsingSyllables(comparisonSyllables); + var sut = new NameGenerator() + .UsingSyllables(x => x + .WithVowels(vowels) + .WithConsonants(consonants) + .WithRandom(new Random(seed))) + .UsingRandom(new Random(seed)); + + var comparison = new NameGenerator() + .UsingSyllables(x => x + .WithVowels(vowels) + .WithConsonants(consonants) + .WithRandom(new Random(seed))) + .UsingRandom(new Random(seed)); for (int i = 0; i < 1000; i++) { diff --git a/Syllabore/Syllabore.Tests/SyllableGeneratorTests.cs b/Syllabore/Syllabore.Tests/SyllableGeneratorTests.cs index f739f93..34865d9 100644 --- a/Syllabore/Syllabore.Tests/SyllableGeneratorTests.cs +++ b/Syllabore/Syllabore.Tests/SyllableGeneratorTests.cs @@ -738,15 +738,16 @@ bool isTrailingConsonantSequenceExpected } [TestMethod] - [DataRow(0)] - [DataRow(12345)] - public void SyllableGenerator_StaticRandomSeed_CreatesPredictableOutput(int seed) + [DataRow("aeiou", "strlmnp", 0)] + [DataRow("aeiou", "strlmnp", 12345)] + public void SyllableGenerator_StaticRandomSeed_CreatesPredictableOutput( + string vowels, + string consonants, + int seed + ) { - var sut = new SyllableGenerator("aeiou", "strlmnp"); - sut.Random = new Random(seed); - - var comparison = new SyllableGenerator("aeiou", "strlmnp"); - comparison.Random = new Random(seed); + var sut = new SyllableGenerator(vowels, consonants).WithRandom(new Random(seed)); + var comparison = new SyllableGenerator(vowels, consonants).WithRandom(new Random(seed)); for (int i = 0; i < 1000; i++) { diff --git a/Syllabore/Syllabore/NameGenerator.cs b/Syllabore/Syllabore/NameGenerator.cs index d3cc81d..5985003 100644 --- a/Syllabore/Syllabore/NameGenerator.cs +++ b/Syllabore/Syllabore/NameGenerator.cs @@ -373,6 +373,17 @@ public NameGenerator UsingProbability(Func + /// Sets the instance of + /// this class will use to simulate randomness during + /// the name generation process. + /// + public NameGenerator UsingRandom(Random random) + { + this.Random = random; + return this; + } + /// /// /// Sets the maximum number of generation retries before an exception is thrown. diff --git a/Syllabore/Syllabore/SyllableGenerator.cs b/Syllabore/Syllabore/SyllableGenerator.cs index 54434ce..348b9b5 100644 --- a/Syllabore/Syllabore/SyllableGenerator.cs +++ b/Syllabore/Syllabore/SyllableGenerator.cs @@ -608,6 +608,16 @@ public SyllableGenerator WithProbability(Func + /// Sets the instance of to use when + /// simulating randomness during the syllable generation process. + /// + public SyllableGenerator WithRandom(Random random) + { + this.Random = random; + return this; + } + /// /// Specifying a value of true will permit generation of empty strings /// as syllables. This is a scenario if there are no vowels/consonants to choose from or if the probability