create numbers using SortedSet and return as List

camelCase local variables
This commit is contained in:
onyx-and-iris 2024-09-29 03:09:50 +01:00
parent 8224684ddc
commit 9c0baaa482

View File

@ -5,21 +5,20 @@
/// <summary> /// <summary>
/// Simple algorithm for generating a list of unique numbers of Limits.Count size /// Simple algorithm for generating a list of unique numbers of Limits.Count size
/// </summary> /// </summary>
/// <param name="Limits">Defines the amount of numbers to generate, the max and min values</param> /// <param name="limits">Defines the amount of numbers to generate, the min and max values</param>
/// <returns>The list of numbers is returned sorted in ascending order.</returns> /// <returns>Numbers are returned as a sorted set.</returns>
public static List<int> Generate(Limits Limits) public static SortedSet<int> Generate(Limits limits)
{ {
List<int> Candidates = Enumerable.Range(Limits.Lower, Limits.Upper).ToList(); List<int> candidates = Enumerable.Range(limits.Lower, limits.Upper).ToList();
List<int> Numbers = []; SortedSet<int> numbers = [];
for (int i = 0; i < Limits.Count; i++) for (int i = 0; i < limits.Count; i++)
{ {
int RandomIndex = Random.Shared.Next(Candidates.Count); int RandomIndex = Random.Shared.Next(candidates.Count);
Numbers.Add(Candidates[RandomIndex]); numbers.Add(candidates[RandomIndex]);
Candidates.RemoveAt(RandomIndex); candidates.RemoveAt(RandomIndex);
} }
Numbers.Sort(); return numbers;
return Numbers;
} }
} }
} }