Example #1
0
 public static void Sort(int maxAllowedThreads)
 {
     if (!SortedListIsCreated)
     {
         SortedWordList.Clear();
         if (IsAvailable("shuffled"))
         {
             SortedWordList      = ShuffledWordList.AsParallel().WithDegreeOfParallelism(maxAllowedThreads).OrderBy(word => word).ToList();
             SortedListIsCreated = true;
         }
     }
 }
Example #2
0
        public static void Shuffle()
        {
            ShuffledWordList.Clear();
            // Fisher-Yates shuffle.
            Random rnd = new Random();
            int    n   = SortedWordList.Count;

            for (int i = n - 1; i >= 0; i--)
            {
                int    randomIndex = rnd.Next(0, i + 1); // Get random index between 0 and remaining unshuffled list item count.
                string tempString  = SortedWordList[i];
                ShuffledWordList.Add(SortedWordList[randomIndex]);
                SortedWordList[randomIndex] = tempString;
            }
            ShuffledListIsCreated = true;
        }