@@ -39,7 +39,7 @@ public class Lipsum : IRandomizerPlugin<string>
39
39
private readonly int maxSentences ;
40
40
private readonly int minWords ;
41
41
private readonly int maxWords ;
42
- private readonly int seed ;
42
+ private readonly int ? seed ;
43
43
44
44
/// <summary>
45
45
/// Words for the standard lorem ipsum text.
@@ -130,6 +130,8 @@ public class Lipsum : IRandomizerPlugin<string>
130
130
/// </summary>
131
131
private readonly Dictionary < LipsumFlavor , string [ ] > map ;
132
132
133
+ private System . Random random ;
134
+
133
135
/// <summary>
134
136
/// Initializes a new instance of the <see cref="Lipsum"/> class.
135
137
/// </summary>
@@ -152,7 +154,7 @@ public class Lipsum : IRandomizerPlugin<string>
152
154
/// The max words of the generated text.
153
155
/// </param>
154
156
/// <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.
156
158
/// </param>
157
159
public Lipsum ( LipsumFlavor flavor , int paragraphs = 3 , int minSentences = 3 , int maxSentences = 8 ,
158
160
int minWords = 10 , int maxWords = 50 , int ? seed = null )
@@ -172,7 +174,8 @@ public Lipsum(LipsumFlavor flavor, int paragraphs = 3, int minSentences = 3, int
172
174
{ LipsumFlavor . LeMasque , LeMasque }
173
175
} ;
174
176
175
- this . seed = seed . HasValue ? seed . Value : Environment . TickCount ;
177
+ this . seed = seed ;
178
+ this . random = new System . Random ( ) ;
176
179
}
177
180
178
181
/// <summary>
@@ -181,20 +184,23 @@ public Lipsum(LipsumFlavor flavor, int paragraphs = 3, int minSentences = 3, int
181
184
/// <returns>Random data for type <see cref="T"/></returns>
182
185
public string GetValue ( )
183
186
{
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
+ }
186
191
192
+ var array = this . map [ this . flavor ] ;
187
193
var result = new StringBuilder ( ) ;
188
194
189
195
for ( var i = 0 ; i < this . paragraphs ; i ++ )
190
196
{
191
- var sentences = rnd . Next ( this . minSentences , this . maxSentences + 1 ) ;
197
+ var sentences = this . random . Next ( this . minSentences , this . maxSentences + 1 ) ;
192
198
for ( var j = 0 ; j < sentences ; j ++ )
193
199
{
194
- var words = rnd . Next ( this . minWords , this . maxWords + 1 ) ;
200
+ var words = this . random . Next ( this . minWords , this . maxWords + 1 ) ;
195
201
for ( var k = 0 ; k < words ; k ++ )
196
202
{
197
- var word = array [ rnd . Next ( array . Length ) ] ;
203
+ var word = array [ this . random . Next ( array . Length ) ] ;
198
204
if ( k == 0 )
199
205
{
200
206
word = System . Globalization . CultureInfo . CurrentCulture . TextInfo . ToTitleCase ( word ) ;
0 commit comments