Random in formula

How do I choose a random entity with a formula? I’m trying to populate a field in an automation, but I couldn’t find random anywhere.


Hah, I’ve been meaning to ask about this too. I don’t think there’s an actual random function, but maybe there is a workaround… Are you using this for some kind of Spaced Repetition or similar thing? :grin: I was wanting to add a random “mindset” reminder to each day from a set of them… In a non-personal context (i.e. professional use cases), what might be some examples of the value of “random”?

I just thought of it because Tana added random initializing this morning and I remembered how much I use it.

So I incorporate randomness a TON into my life and workflow because I firmly believe that the Universe, God, life force, fate, whatever you want to call it… has a much better imagination than I do and I want to create space for that to be injected into my life, create some opportunities for serendipity, be surprised and make sure I’m getting to things that I would unconsciously push away (humans aren’t good at random).

So I currently use Coda for this (sometimes Obsidian and AppleScript). But here are the areas where I apply it:

  • Reviewing and cleaning up notes.
  • Creating workouts (every day I have a workout created for me with a random type, number of exercises, exercises, reps, sets,etc). I have my goal weight calculated for me based on my oura ring readiness score, my previous max calculated 1RM and the number of reps.
  • Generating my meals for the day
  • Generating a CBD strain for the day
  • Choosing a topic to research
  • Articles/Books to read
  • Which posts to put on Social Media
  • Which drill to do out of communication exercises I’ve learned
  • Nightly mobility and stretching randomly chosen from stretches that match up with the muscle groups I worked out in the random workout
  • Movies/TV Shows to watch
  • Which instrument to practice that day and what songs to play
  • Which developmental exercises to practice with my 4 month old
  • Skills to practice with my dog
  • Which board game to play
  • Activities to do that day.

So, you see, I REALLY need a random function lol!


Wow, I love this! Amazing and inspiring. I have wanted to incorporate just a few of these myself (and I have some ways of resurfacing things in a pseud-random way). But actually having a direct way to do this sort of thing would be fantastic.

May I just say (outside of the direct subject of this topic :smile:) that I love having another “quantified self”, serious individual use person in here. So glad you’ve joined us and I hope you’re able to stick around!

1 Like

There’s no modulo operator in Formulas (?) so you will need to do this in a Script.

You can create a Rule that fires when an entity is created (or updated), and runs a Script to fill a numeric field with a random value:


const fibery = context.getService('fibery');
for (const entity of args.currentEntities) {
    await fibery.updateEntity(entity.type, entity.id, {
        Random: Math.random()


(I’m going to have to learn Javascript aren’t I…)


I have been increasingly thinking so too. :confused: It’d be good for me for many other reasons too, but dangit, I don’t wanna! :sob: :laughing:

1 Like

Same! I know we’ve been floating around the same circles for a while but it’s nice to finally connect!

1 Like

Circling back to this. Could I generate a random relation instead of a number?

Example: I have a table with a row for each day (2023-01-16, 2023-01-17, etc) I also have a table where each row is an exercise (Chest Press, Front Squat, etc). Could I generate a random Exercise relation each time a new day row is created?

If you can generate a random number, you can generate a random ID string, which will get you a random entity in a database.
Unfortunately, ID’s are not re-used, so any ID you generate could belong to an entity that has been deleted (or greater than the highest value created so far).
Accordingly, you would need to write some clever helper code to

  • determine the maximum ID value used in any given database
  • ‘re-roll the dice’ if you hit a non-used ID.

It’s not impossible though :slight_smile:

Create a Rule to trigger on creating a new Day entity, and use a script to:

  1. Retrieve the UUIDs of all/some entities in the Exercise DB.
  2. Randomly select one.
  3. Link the selected Exercise entity to the new Day entity.

For exercises though, you probably don’t want a “real” random selection, which would tend to be quite uneven and have lots of repetition; you probably would want something that would give you a more evenly-distributed but “unpredictable” selection.

1 Like

Actually, this is nice lateral thinking.
I could imagine that you could easily create an automation that generates a list of the IDs of all entities in a given database, and then randomly picks a row from the list.
You could even do it without scripting I bet!

:point_up: indeed

Now that the AI is released (experimentally), you could try using it in an automation so that it will make a random choice from a list of options, e.g.