How to Randomly Sort a Table in Notion
Date: 2025-11-19 | create | notion |
I've been playing around with building a knowledge garden for myself now that I've moved back to Notion. It's a mix of the Zettelkasten and Digital Garden note taking methods.
I wanted a way to bubble up a random note to review semi-regularly and couldn't find a simple formula I like so here's the one I went with.
What I want in a random sort
For my sort needs, I want something where:
- Each page gets a unique value - So I can sort them against each other in a database.
 - Different values on each load - So each time I visit it the order is randomized.
 - The sort has no (discernible) patterns - so it's randomized enough for my purposes.
 
Notion Table Random Sort
To randomly sort a database in Notion, I created a Random property with a formula that computes a random number based on the current time and page.
- Each page gets a unique value - We use pageId to get this. I've also added in last edited time to add a bit more entropy here for each page as it can change over time.
 - Different value on each load - We use the current timestamp to get this. It only updates each minute but that's fast enough for my usecases (Notion only provides time up to minute granularity).
 - The sort has no (discernible) patterns - We mix the factors along with some prime numbers and a modulo to get this.
 
Formula:
/* Create a pseudo-random number that changes on each page load (minute granularity) */
lets(
    /* Get the page ID as a stable seed */
    pageId, id(),
    /* Create a numeric value from page ID */
    idValue, toNumber(replaceAll(id(), "[a-f]", "")),
    /* Current ms - minute granularity */
    nowMs, toNumber(now()),
    /* Get the last edited time ms - minute granularity*/
    lastEditedTime, toNumber(formatDate(prop("Last Updated"), "X")),
    /* Mix the values together for pseudo-randomness */
    seedValue, (idValue * 9973) + (nowMs * 7919) + (lastEditedTime * 6421),
    /* Generate a number between 0-9999 */
    abs(seedValue % 10000)
)
The code is well commented but I'll describe it here anyway:
- Use a 
letsblock which allows a series of variables to be set with the final element being the return value - Transforms the pageId from a Hex value to a number by stripping all the letters
 - Gets the current timestamp in ms (minute granularity)
 - Gets the last edited time in ms (minute granularity)
 - Mixes the values together using primes to get a better distribution across the number space
 - Modulo 10k to pull off the least significant digits for comparison - this could be higher if you have a really big db but at that point you'll prob be running into scalability issues w Notion databases.
 
Next
This is a pseudo-random so I wouldn't use this in production code but it works well enough for my purposes so I'm sticking w it.
If you liked this post, you might also like:
Want more like this?
The best way to support my work is to like / comment / share for the algorithm and subscribe for future updates.
