I'm not sure what kind of terminology to use in this so please edit the title to fit as necessary.
For learning purposes, I'm trying to make a screensaver that displays images randomly from a specified folder. Yes, Windows already comes with this but again, learning purposes. Though I'd prefer to learn the proper way the first time instead of having to go back through and relearn how to properly do things.
Now I already have it randomly choosing images and displaying them, etc. What I'd like to do is randomize based on how many times a specific image has been loaded.
For example:
Image 1: 0 views(20%) : 1 view (19%)
Image 2: 0 views(20%) : 0 views(24%)
Image 3: 0 views(20%) : 1 view (19%)
Image 4: 0 views(20%) : 2 views(14%)
Image 5: 0 views(20%) : 0 views(24%)
This way Image 2 and Image 5 would have the highest chance of being shown next.
I've been at this for a while but I'm not sure what's wrong as it's simply grabbing the next pic along the list. I tried to group them by finding all the pictures with the same number of views and then randomizing through that list but it doesn't seem to exactly work the greatest. Here's the code I have for displaying the pictures:
Random rnd = new Random();
string file = "";
int totalViews = 0;
List<string> array = new List<string>();
void ShowPicture()
{
array.Clear();
label1.Text = "";
foreach (Screen screen in Screen.AllScreens)
{
bool done = false;
while (!done)
{
int rand = rnd.Next(100), total;
foreach (string info in files.Keys)
{
total = (100 / files.Count) - (files[info] * (files.Count - 1)) + totalViews;
if (total >= rand)
{
foreach (string tmp in files.Keys) if (total >= files[tmp]) array.Add(tmp);
label1.Text = "Percentage for image: " + total;
done = true;
break;
}
}
}
file = array[rnd.Next(array.Count)];
files[file]++;
totalViews++;
Image image = Image.FromFile(file);
pictureBox1.Image = image;
label1.Text += "\nTotal Views: " + totalViews;
}
}
I hope this is clear enough and thanks in advance.