ljnath / RandomString4Net

.NET library to generate N random strings of M length from various categories
MIT License
9 stars 2 forks source link

forceUnique can generete less strings than requested #3

Closed Mart-Bogdan closed 7 months ago

Mart-Bogdan commented 10 months ago

In this loop if this option is set

https://github.com/ljnath/RandomString4Net/blob/f01e28844ff909906fcf5cd08ab4aaaf9586a33e/RandomString4Net/RandomString.cs#L194-L206

it just skips current string (index) https://github.com/ljnath/RandomString4Net/blob/f01e28844ff909906fcf5cd08ab4aaaf9586a33e/RandomString4Net/RandomString.cs#L202-L203

But it should retry to generate non repetitive string.

P.S. same for second method

https://github.com/ljnath/RandomString4Net/blob/f01e28844ff909906fcf5cd08ab4aaaf9586a33e/RandomString4Net/RandomString.cs#L239-L240

ljnath commented 10 months ago

@Mart-Bogdan , thank you for raising this issue. Can you please explain it just skips current string (index) and share a test scenario.

I have tried RandomString.GetStrings(Types.NUMBERS, 2, 10, false, true, forceOccuranceOfEachType: false) , I did get 2 random strings

ljnath commented 7 months ago

This is expected as the number of random strings will decreased when all characters are mandatorily used.