I've seen a few examples but none so far in C#, what is the best way to select a random file under a directory?
In this particular case I want to select a wallpaper from "C:\wallpapers" every 15 or so minutes.
Thanks.
I've seen a few examples but none so far in C#, what is the best way to select a random file under a directory?
In this particular case I want to select a wallpaper from "C:\wallpapers" every 15 or so minutes.
Thanks.
why not just:
Use the
Directory.GetFiles(...)
to get the array of filenames and use theRandom
class to select a random file.select random file from directory
If you're doing this for wallpapers, you don't want to just select a file at random because it won't appear random to the user.
What if you pick the same one three times in a row? Or alternate between two?
That's "random," but users don't like it.
See this post about how to display random pictures in a way users will like.
Get all files in an array and then retrieve one randomly