Bases: Add a simple hash function or allow random() function to take seed-values as input

Use case or problem

Important note: This is based on the information available in the Functions Docu

Dataview has a hash function which can be used to create a pseudo-random string based on the input. This can then be used to sort the files in a random order.

Adding in some quantized time information allows that random order to change in a periodic interval. For example, the query code below sorts all notes in a random order which changes every hour, and shows me the first 10 results.

...
SORT hash(dateformat(date(now), "yyyy-MM-dd HH"), file.name)
LIMIT 10

It would be neat to have this option available in bases. It provides a way of looking at a set of notes in a unpredictable way, but is slow enough that you can work with it. And you can’t accidentally modify it, like you might be if there was a “randomly sort notes in base” functionality.

Proposed solution

Add a function hash() that hashes an input

Current workaround (optional)

Related feature requests (optional)

edit: formulated feature request, pressed ctrl+enter too soon

3 Likes

Since this feature request the random() function has been added to bases, which returns a random number between 0 and 1. This can be used to sort notes in a random order.
However, this value changes a lot (e.g. when switching views or when closing and reopening the base tab), making it hard to use.

A change to the random() function which would also address the above feature request would be to allow it to take an input which acts as the seed for the random number generation, leading to it always returning the same random number. E.G. random(1234) return 0.25 while random("2026-03-05 10:57") returns 0.314159.
This would allow us users to fix the randomness in place and have it change based on some other factor, like with every hour change as described in the feature request.