Ejemplo n.º 1
0
 protected void RandomlyBindPixelsIntoPairs(PixelCollection pixelCollection, int pixelsToSelect)
 {
     lock (pixelCollection)
     {
         pixelCollection.OrderByPoints();
         _pixelPairs = new List <PixelPair>();
         var alreadySelectedPixelsIds = new List <int>();
         var randomGenerator          = new Random();
         for (int index = 0; index <= pixelsToSelect - 1; index++)
         {
             if (!alreadySelectedPixelsIds.Contains(index))
             {
                 alreadySelectedPixelsIds.Add(index);
                 int newIndex = randomGenerator.Next(index + 1, pixelsToSelect);
                 while (alreadySelectedPixelsIds.Contains(newIndex))
                 {
                     newIndex = randomGenerator.Next(index + 1, pixelsToSelect);
                 }
                 alreadySelectedPixelsIds.Add(newIndex);
                 _pixelPairs.Add(new PixelPair()
                 {
                     First  = pixelCollection[index],
                     Second = pixelCollection[newIndex],
                 });
             }
         }
     }
     return;
 }