disposedtrolley / literary-screensaver

A macOS screensaver that displays the time in the form of literary quotes. Inspired by https://www.instructables.com/id/Literary-Clock-Made-From-E-reader/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Randomise quote for times with multiple quotes

disposedtrolley opened this issue · comments

It would be good if the screensaver selected a random quote if a particular time has multiple quotes associated with it. Currently it always picks the first matching quote that’s found.

This change would require modifying the data structure the quotes are stored in to a hash map, where each key is a time and the corresponding value is an array of quotes. To obtain a quote, we would just need to access the key, and then pick a random element of the corresponding array bounded by its length.

This setup would also make finding the quote more efficient as we no longer need to iterate through the array to search.