feat: hash() - Generate a unique number based on input #2272
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Based on a unique combination of a seed, text and a variant number, it generates a fixed number which can be used for sorting in a random order. Typical seed could be the date of today, the text a file name, and the variant could be the line number of a list/task item.
As discussed in #2252 this is the alternate PR just having a
hash()
function, which is a simple logic, but still provides the needs necessary for sorting any list in a random order, but with fixed value for a given input sequence.Given a date as the seed, this can be used to sort lists of files/tasks/lists, and then return a random item of that list, and the item for that given date will remain the same (as long as the other parameters stay the same). This deals with an issue of using dataview to receive random items, where it'll change for every refresh of the random query.
See also https://jsperf.app/bowuze for the reasoning why this particular hash function was used.