Inline Random-Note Link Pathing: Possible, or a Pipe Dream?

Hoi there, noob here. :wave: Thanks for taking a look!

What I’m trying to do

I am attempting to generate a file path to a random note out of a specific folder, which I will then place in a “Random Note” link.

i.e., [[ Root Folder Which Never Changes/Path/to/random/note.md | Random Note ]]

This link to a random note will be lovingly placed in a card along with all of its buddies.

Things I have tried

Templater and Dataview have been my sword and shield, and both to tantalizingly close effect. I have a great sauce from this very forum that has allowed me to create a block of DataviewJS to generate a Random Note path with a consistent “Random Note” name override pretty effectively.

let pages = dv.pages('"01 - The World"')
let random = Math.floor(Math.random() * (pages.length - 1))
let randomNote = pages[random].file.name

dv.paragraph("[[" + randomNote + "| Random Note]]")

As for Templater, I can make all sorts of great Templates for pages, sure, but the user-defined functions remain beyond me. (For now.)

I’ve got all the ingredients for a spectacularly nutritious randomizer. I just don’t know how to make it stay inline. If you’re willing to help a poor soul out, I’d really appreciate any and all pointers given. If this is impossible, I’ll hear it! Better to know I’m being foolish with the tools than to keep trying, in that case.

TL;DR: Although I know there’s a random note feature in Obsidian, yes, I am being extra.

There has been various answers related to this question, so if you search for random notes in this forum, you’ll get many examples on how to do this, and the caveats related to them.

Lately there has also been the addition of the hash() function to a standard query allowing for a pure query to produce a random note where you through the seed can control when (or if) to refresh the result. The code you presented will present a new file each time the query is executed…

1 Like

Great feedback! Thank you! :two_hearts:

I have been trawling these forums, so I’ll take another look and see if I can make sense of them. I have seen you on a lot of the posts that have addressed this, so I’m not surprised by your answer! :grin:

hash() function, you say? I’ll take a gander! Thanks for the lead!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.