Generic Random List
RandomList it’s basically a Collection of items that can be iterated randomly.
// Creating a RandomList of string
var randomList = new RandomList<string>();
// Adding items
randomList.Add("First");
randomList.Add("Second");
randomList.Add("Third");
Then, when the collection is iterated:
The elements are not in the same order in wich they were added. That’s because RandomList randomizes the order of the elements.
It is available on Nuget. To install via Package Manager Console:
PM> Install-Package RandomList.Core
Or browsing “RandomList” through NuGet VS VSIX.
Having a RandomList, you can randomize the order of the elements again.
var randomList = new RandomList<int>{ 1, 2, 3, 4};
// actual order of elements: 2, 1, 4, 3
//Randomizing
randomList.Randomize();
// new order of elements: 3, 1, 2, 4
Having a RandomList, you can get an element randomly.
var randomList = new RandomList<int>{ 1, 2, 3, 4};
// Getting an item
int item = randomList.GetItemRandomly();