@@ -39,7 +39,7 @@ public class Lipsum : IRandomizerPlugin<string>
3939 private readonly int maxSentences ;
4040 private readonly int minWords ;
4141 private readonly int maxWords ;
42- private readonly int seed ;
42+ private readonly int ? seed ;
4343
4444 /// <summary>
4545 /// Words for the standard lorem ipsum text.
@@ -130,6 +130,8 @@ public class Lipsum : IRandomizerPlugin<string>
130130 /// </summary>
131131 private readonly Dictionary < LipsumFlavor , string [ ] > map ;
132132
133+ private System . Random random ;
134+
133135 /// <summary>
134136 /// Initializes a new instance of the <see cref="Lipsum"/> class.
135137 /// </summary>
@@ -152,7 +154,7 @@ public class Lipsum : IRandomizerPlugin<string>
152154 /// The max words of the generated text.
153155 /// </param>
154156 /// <param name="seed">
155- /// The seed for the random to get the same result with the same seed.
157+ /// The seed for randomizer to get the same result with the same seed.
156158 /// </param>
157159 public Lipsum ( LipsumFlavor flavor , int paragraphs = 3 , int minSentences = 3 , int maxSentences = 8 ,
158160 int minWords = 10 , int maxWords = 50 , int ? seed = null )
@@ -172,7 +174,8 @@ public Lipsum(LipsumFlavor flavor, int paragraphs = 3, int minSentences = 3, int
172174 { LipsumFlavor . LeMasque , LeMasque }
173175 } ;
174176
175- this . seed = seed . HasValue ? seed . Value : Environment . TickCount ;
177+ this . seed = seed ;
178+ this . random = new System . Random ( ) ;
176179 }
177180
178181 /// <summary>
@@ -181,20 +184,23 @@ public Lipsum(LipsumFlavor flavor, int paragraphs = 3, int minSentences = 3, int
181184 /// <returns>Random data for type <see cref="T"/></returns>
182185 public string GetValue ( )
183186 {
184- System . Random rnd = new System . Random ( this . seed ) ;
185- var array = this . map [ this . flavor ] ;
187+ if ( this . seed . HasValue )
188+ {
189+ this . random = new System . Random ( this . seed . Value ) ;
190+ }
186191
192+ var array = this . map [ this . flavor ] ;
187193 var result = new StringBuilder ( ) ;
188194
189195 for ( var i = 0 ; i < this . paragraphs ; i ++ )
190196 {
191- var sentences = rnd . Next ( this . minSentences , this . maxSentences + 1 ) ;
197+ var sentences = this . random . Next ( this . minSentences , this . maxSentences + 1 ) ;
192198 for ( var j = 0 ; j < sentences ; j ++ )
193199 {
194- var words = rnd . Next ( this . minWords , this . maxWords + 1 ) ;
200+ var words = this . random . Next ( this . minWords , this . maxWords + 1 ) ;
195201 for ( var k = 0 ; k < words ; k ++ )
196202 {
197- var word = array [ rnd . Next ( array . Length ) ] ;
203+ var word = array [ this . random . Next ( array . Length ) ] ;
198204 if ( k == 0 )
199205 {
200206 word = System . Globalization . CultureInfo . CurrentCulture . TextInfo . ToTitleCase ( word ) ;
0 commit comments