Random numbers in Notion? Is that even possible? As of now, Notion formulas don’t offer an easy way to create a random number. But with a little bit of a workaround, it’s definitely possible to introduce random numbers to your Notion workspace and start creating a shuffle for Notion. What’s more, you can even use these random numbers to show only a single database entry, which is another feature that Notion doesn’t seem to support at first glance.
Want to learn about all the other cool Notion features? Check out my complete (and free) Notion Tutorial.
Let’s dive in and see how it’s done.
What are random numbers in Notion?
Random numbers are an important building block to create certain features in your Notion workspace. They are necessary for shuffle functions, unique identifiers (GUIDs in Notion) or to get Notion to only show one database entry at a time.
Most programming languages have a simple command to have a program return a random number for a given range. In Notion however, there’s no single formula command to get a random number.
How to get random numbers in Notion
You can get a sufficiently random number in Notion by using a fairly complex formula that combines several other numbers. You can actually get a variety of random numbers that way. Which formula to choose will depend on your specific use case.
All of these formulas are designed to return fairly large numbers. That’s because they are designed to support shuffle functions in Notion, where you don’t want to have a lot of the same number.
Random Dynamic Number in Notion
To get a random dynamic number with just one property, use the following formula:
mod(mod((toNumber(slice(replaceAll(id(), "[a-z]", ""), 0, 8))) * 1.00011979e+8 + 5.00067713e+8, 9.00066731e+8) * mod(timestamp(now()) * 8.00067089e+8 + 8.00068411e+8, 8.00053967e+8) + 9.00067309e+8, 9.00066571e+8)
The number is dynamic, which means that it will change every time you reload the page.
Random Static Number in Notion
To get a random static number, you will need two properties in your database. One Created Time property and a formula property with the below formula:
mod(mod(timestamp(prop("Created Time")) * 1.00011979e+8 + 5.00067713e+8, 9.00066731e+8) * mod(toNumber(slice(replaceAll(id(), "[a-z]", ""), 0, 8)) * 8.00067089e+8 + 8.00068411e+8, 8.00053967e+8) + 9.00067309e+8, 9.00066571e+8)
The number is static, which means that it will never change.
Random Timestamp in Notion
You can combine the two numbers from above to create a random timestamp in Notion. Timestamps in Notion are so-called unix timestamps. It’s a fairly large number that represents the total amount of seconds that have passed since January 1st, 1970 UTC.
That might not sound overly exciting, but it’s the key to show only one database item, so it comes in handy quite a bit.
You’ll need two existing properties in your database called Randomizer Dynamic and Randomizer Static with the above formulas:
toNumber(slice(format(prop("Randomizer Dynamic") * prop("Randomizer Static")), 0, 13))
How to get a random daily number in Notion
Using the above method will return a new random number every millisecond, because the timestamp constantly updates. That means you have a new number every time you refresh your Notion page.
In some instances, you might want a slower cadence. If you plan to build a daily inspirational quote in Notion for example, the number should only change once per day.
To get a random number that only updates once a day, you need to first turn the timestamp into today's date and then reconstruct the timestamp for today (without the hour, minute and second component of the normal now() timestamp).
This is best done by using two separate properties. In the first one, turn the now() timestamp into today's date using this formula:
In the second property, use this formula to reverse engineer the timestamp for this date. In this example, the first helper property was called "Day", so change the formula accordingly if you are using a different name.
dateAdd(dateAdd(dateAdd(dateSubtract(dateSubtract(dateSubtract(dateSubtract(dateSubtract(now(), year(now()), "years"), month(now()), "months"), date(now()) - 1, "days"), hour(now()), "hours"), minute(now()), "minutes"), toNumber(slice(prop("Day"), 6, 10)), "years"), toNumber(slice(prop("Day"), 0, 2)) - 1, "months"), toNumber(slice(prop("Day"), 3, 5)) - 1, "days")
How do random numbers in Notion work?
Random number formulas in Notion utilise the mod() function. This function divides two given numbers and returns the rest. That means, if you give it different numbers for every calculation, it will always return a different number without there being a correlation in size (i.e. just because calculation 1 had two lower numbers doesn’t mean that the function will return a lower number than for calculation 2 with two high numbers).
Now all you need is to pass in two different numbers. Initially, Notion had only three different sort of numbers readily available for calculations:
- Created Time (the timestamp of the creation of the database item)
- Last Edited Time (the timestamp of the last modification of the database item)
- now() (the current timestamp)
That somehow limited the creation of random numbers. The first method that I found on reddit utilised the Created Time and the current timestamp, which worked fine but fell short when you bulk-created database entries (because they all shared the same Created Time).
Recently however, Notion introduced id() to its formulas. Using id(), you can return the database id for an entry. That’s a fairly long string of numbers and letters and we can use it as a random number by removing all the letters from the sequence.
With that, we have a more unique way to create random numbers that also works for items that were created at the same time. Now, there’s a chance that some entries end up with the same sequence of numbers in the ID after removing the letters, so you could combine the method above with the Created Time, but it’s probably not necessary in most use cases.
What can you use random numbers in Notion for?
The main purpose of random numbers in Notion is to shuffle through a large amount of database entries or to display only a single entry at a time.
Shuffle functions are great wherever you have a lot of entries and want to be surprised. You could use them to randomly surface notes from your Zettelkasten, suggest random recipes from your meal planner in Notion or to show a random selection of images in a gallery.
They also form the basis if you want to show only a single database item in Notion.
Random Numbers in Notion Cheatsheet & Template
Get the Shuffle in Notion Cheatsheet and my Random Quote Generator in Notion Template and start shuffling your Notion workspace around.