diff --git a/src/harness/BenchmarkDotNet.Extensions/ValuesGenerator.cs b/src/harness/BenchmarkDotNet.Extensions/ValuesGenerator.cs index 25695ecbab1..911b5e47743 100644 --- a/src/harness/BenchmarkDotNet.Extensions/ValuesGenerator.cs +++ b/src/harness/BenchmarkDotNet.Extensions/ValuesGenerator.cs @@ -54,12 +54,10 @@ public static T[] ArrayOfUniqueValues(int count) { T value = GenerateValue(random); - if (!uniqueValues.Contains(value)) - uniqueValues.Add(value); + if (uniqueValues.Add(value)) + result[uniqueValues.Count - 1] = value; } - uniqueValues.CopyTo(result); - return result; } @@ -178,9 +176,10 @@ public static string[] ArrayOfUniqueStrings(int count, int minLength, int maxLen while (unique.Count != count) { - unique.Add(GenerateRandomString(random, minLength, maxLength)); + string randomString = GenerateRandomString(random, minLength, maxLength); + if (unique.Add(randomString)) + strings[unique.Count - 1] = randomString; } - unique.CopyTo(strings); return strings; }