I have a database of thousands of .wav files which I am looking to subset. For every 10 files, I would like to select one file, but since these files are recording at specific time intervals, I want to avoid the scenario that every 10th file occurs at the same time interval. I want to randomise where I select every 10th file from, between 1:10. So far I have come up with the following but it means that at the end of the loop, it crashes as (I think) the range of random numbers doesn't match the range of available files to draw from. I would like to apply this loop to several files of folders so I can leave it running for days without interferring.