private static bool RandomizeWallpapers() { Random rand = new Random(); // Gather potential wallpapers string[] potentialWallpapers = new string[DisplayData.Displays.Length]; for (int i = 0; i < DisplayData.Displays.Length; i++) { ImageType imageTypeToSearchFor = ImageType.None; double staticChance = OptionsData.GetExactFrequency(ImageType.Static); double gifChance = OptionsData.GetExactFrequency(ImageType.GIF); double videoChance = OptionsData.GetExactFrequency(ImageType.Video); ImageType[] imageTypeIndexes = { ImageType.Static, ImageType.GIF, ImageType.Video }; double[] imageTypePercentages = { staticChance, gifChance, videoChance }; imageTypeToSearchFor = rand.NextInWeightedArray(imageTypeIndexes, imageTypePercentages); if (WallpaperData.IsAllImagesOfTypeUnranked(imageTypeToSearchFor)) { MessageBox.Show("Attempted to set a wallpaper to an image type with no valid/ranked images. Wallpaper Change Cancelled [IMAGE TYPE: " + imageTypeToSearchFor + "]" + "\n\nEither change relative frequency chance of the above image type to 0% (Under Frequency in the options menu)" + "or activate some wallpapers of the above image type (Unranked images with a rank of 0 are inactive"); return(false); } int randomRank = GetRandomRank(ref rand, imageTypeToSearchFor); // Find random image path if (randomRank != -1) { Debug.WriteLine("Setting Wallpaper: " + i); potentialWallpapers[i] = WallpaperData.GetRandomImageOfRank(randomRank, ref rand, imageTypeToSearchFor); if (!WallpaperData.GetImageData(potentialWallpapers[i]).Active) { //! This shouldn't happen, if this does you have a bug to fix MessageBox.Show("ERROR: Attempted to set display " + i + " to an inactive wallpaper | A new wallpaper has been chosen"); i--; // find another wallpaper, the selected wallpaper is inactive } } else { Debug.WriteLine("-1 rank selected | Fix Code | This will occur if all ranks are 0"); } } ModifyWallpaperOrder(ref potentialWallpapers); UpcomingWallpapers.Enqueue(potentialWallpapers); return(true); }