I have a c:\config folder which contains several configuration files (config_x).
I would like to be able to choose one of them at random (the program is written in C).
The number of files may change in the future – so needs to be able to query for number of files in the folder.
How can it be done?
Use
FindFirstFileandFindNextFilein a loop. Keep a count of how many files you’ve seen so far (n). On each loop, randomly break out on a1:nchance:You can find a proof of this method in The Art of Computer Programming, Volume 2, Section 3.4.2, by Donald E. Knuth.