mardi 11 février 2020

Python - Randomly sort a list in a reproducible manner [closed]

I want to choose x random elements from a list, and present them to the user. Every hour, the list's oldest item should be removed, and a new one should be added.

However, if the user does not run this program for (say) 3 hours, and then runs it later, the program should respond with a list with 3 new items, and the oldest x-3 items should be the same. This will be done by having the program remember the hour and day that it was last executed, and updating the list accordingly.

However, there's a catch: I don't want to have to store the list, or the state of the random number generator, or even the time that the script was last run. Ideally, I should be able to send this script to someone with the same system time as me and have it output the same list.

One potential way of doing this would be to use the same random seed every time, count how many hours had passed since the Unix epoch start time of 1970-01-01 00:00 (or some other hardcoded date), generate and throw away that many results, and then generate the x results. This would work, but would be very inefficient, especially if the program was updated to add a new list entry more frequently.

How should I implement this?




Aucun commentaire:

Enregistrer un commentaire