mercredi 3 juin 2015

How to pick random images so the newer ones are more likely to be selected in Linux

I have a bash script on a headless Linux server that accepts a file name as parameter and displays the provided image fullscreen on a beamer.

Users can upload images to a shared folder. I want a random picture of that folder to be chosen each few seconds and displayed. But not completely random. I want that the newer (according to its creation time) a photo is, the more likely it is shown. So all old images are shown as well, but the newer ones will be displayed more frequently.

Is there any way (using Bash and the standard unix tools) to select a random picture from the folder (there are no nested folders, and all files end with the suffix ".jpg"), and consider their age, so the probability a picture is chosen is higher the newer it is?

It would be best if this probability is not linear: while seconds matter when the picture is only a few seconds or minutes old, there does not need to be a huge difference between a picture that is 2 hours or one that is 2 hours and 15 minutes old.




Aucun commentaire:

Enregistrer un commentaire