u/Fit-Hat-9562

▲ 18 r/Notion

Long time lurker, first time poster :) I have a master's degree in biostatistics so I learned coding through SAS/R and transferred my skills over to notion. I have a lot of pages that function really efficiently with formulas, buttons, and automations so maybe I'll start sharing more of them.

Essentially I've had a Recipe/Shopping List page for years where I have all my recipes visible and I can press "add" and the ingredients get added to my shopping list, but I always wanted a random recipe generator so if I didn't know what to cook, I could have it choose it for me, but I could find no help on the internet and couldn't figure it out (rage quit several times). Today I finally said I was going to sit down and not leave until I had it. (If you want an explanation for the recipes and shopping list I can do that later).

Here is an explanation of a random page generator.

You will need 3 databases:

  • Main Database - Will contain all the pages you want to be part of the randomization.
    • e.g. if you're doing a recipe randomization this is where all your recipes will go
  • Random Database - A hidden database that you essentially never touch again that does all the work for you
  • Button Database - One database that only has 4 properties that functions as your randomizing button

*All my relations are 2-way (idk just makes things easier)

Step 1 - create blank databases

  • Create the 3 separate databases
    • Or if you have one you already want as the main database, add 2 more blank ones
    • AGAIN name them MAIN, RANDOM, and BUTTON (or get confused at your own risk)

Step 2 - add starting properties

Here is a list of all the databases and their STARTING properties, we will add more

ADD THEM IN THIS ORDER

Button Database

1 PAGE ONLY (name it whatever, i named mine Random Recipe Generator)

  • RELATION property, to Main Database (2-way and all pages you want to be randomized inside it)
  • NUMBER property, name it SEED, set it to 0

Random Database

1 PAGE ONLY (name it whatever, I named mine Pick (this database is hidden it really doesn't matter)

  • RELATION property to Main Database (2-way and add all pages you want to be randomized inside it)

Main Database

AS MANY PAGES AS YOU WANT

  • *RELATION property to Button Database (2 way, should already exist if you started it in the button database)
  • ROLLUP property from Button Database, name it SEED
    • target property is the SEED Property
    • Calculate Min
  • *RELATION property to Random Database (2 way, should already exist if you started it in the button database) - NAME IT RANDOM REL (we need RANDOM for later)
  • FORMULA property, name it RANDOM ID, all pages you want to be randomized
    • formula:
    • mod(pow(mod(toNumber(replaceAll(id(), "[^0-9]","")), 9973) + toNumber(Seed) * 7919, 3 ), 1000000 )
    • ***MAKE SURE SEED IS CONVERTED TO THE ROLLUP PROPERTY SEED, IT DOESN'T PASTE RIGHT

Step 3 - More properties

Button Database

  • BUTTON property, name it GO!
    • Automation:
    • edit this page
    • property: SEED
    • formula: This page.Seed+1

Random Database

  • ROLLUP property, from the MAIN DATABASE, name it RANDOM ID

    • target property: RANDOM ID
    • calculate Min
  • ROLLUP property, from the MAIN DATABASE, name it LIST

    • target property: RANDOM ID
    • calculate: show original
  • FORMULA property, name it LIST NUMBER

    • formula:
    • findIndex(List,current==Random id)
  • FORMULA property, name it RANDOM CHOICE

    • formula:
    • MAIN.at(toNumber(List Number))

Main Database

  • ROLLUP property, from the RANDOM DATABASE, name it RANDOM CHOICE
    • target property: RANDOM CHOICE
    • calculate: show original
  • FORMULA property, name it RANDOM
    • formula:
    • if(format(Random Choice)==Name,true,false)

Step 4: DISPLAYING YOUR RANDOMIZATION

BUTTON

- Gallery view

- Layout

  • no preview

- Property visibilit

  • only name and GO! button

MAIN

- EASY: sort database by RANDOM, random choice comes to the top

- HARD (not really but slightly more work):

  • create a new view of MAIN database
  • filter so random is checked

RANDOM

- Hide under toggle heading

Now when you press GO! your random page will change each time. I hope this helps someone :)

u/Fit-Hat-9562 — 22 days ago