How to make a random shuffle gallery view in Notion

October 17, 2022

Notion is a powerful cross-platform knowledge management tool. I have been taking digital notes for years. Needless to say, I have experimented with many note-taking systems. Recently, I have switch over to Notion for both personal and business note-taking. With the ability to generate database within notes and strong visuals, my knowledge management system is taken to a new level.

Although Notion allows creating different views of a database, all views are static. They can be sorted in different ways, but there’s no built-in shuffled view.

What if you want to create a deck of flash card for memorization? A deck of recipes that are displayed randomly to give you idea what to cook tonight? You cannot do that in any of the database options.

In this post, I will teach you a way to use formula to create a shuffled view in Notion.

You can download the final template here.

Generating a random number in Notion

First, create a new database. There’s no function in formula to generate random numbers, but you can take advantage of the id() function which returns the unique identifier of each entry. It returns something like



It appears that Notion generates a hexadecimal random number for each entry. To get a random decimal random number, remove the values a to f:

replaceAll(id(), "[a-f]", "")


The number is coming out way too long. Notion will have problem doing math with it. Let’s trim it to 6 digits and convert it from text string to number type.

toNumber(slice(replaceAll(id(), "[a-f]", ""), 0, 6))


Now, you get a random number per entry. But there’s one problem: The random number doesn’t change. It’s static. We cannot use it to shuffle a view. We need something that would change over time… like a clock…

Time stamp as randomizer

We can use the timestamp function to convert the present time to a number, corresponding to the number of milliseconds from the reference time.



The number is too big. Reducing it to 6 digits using mod function

mod(timestamp(now())/10000, 123456)


Final formula for timer randomized number for Notion

To generate a random number per entry that changes over time, we multiple the random number with the timestamp, and limit its range by applying a final mod function.

Putting everything together, here’s the formula that generates a random number that changes over time:

mod(toNumber(slice(replaceAll(id(), "[a-f]", ""), 0, 4))* mod(timestamp(now())/10000, 123456), 123456)

Now I am going to show you how to create a random gallery view step-by-step

  1. Create a database
  2. Add a new column with type formula and name it random
Create database
  1. Click on the first cell of the newly created random column. Copy and paste the above formula and click done.
Paste formula
  1. Add more rows to the database. The random column should be automatically populated with random values.
Add row
  1. Add a new gallery view.

  2. Sort the view by the random property in descending order.

Sort random column

Now you get a shuffled gallery view! Since return value of the now() function is updated every minute, the view is shuffled every minute.


Notion does not have a random number generator, but we can hack some functions together to get pretty close. Now, you can go make it…! Or you can download the template here.

In an upcoming post, I will show you how to make this random inspirational quotes for Notion. It involves some advanced techniques in Notion but I promise it will be fun!

Check out my iOS keyboard designed for Notion.

Follow me on Twitter to receive content like this.

Subscribe to my newsletter to receive weekly updates.

Check out my Markdown Keyboard for iPhone and iPad