# Jump to Random Page within a Folder

**URL:** <https://community.silverbullet.md/t/jump-to-random-page-within-a-folder/3991>\
**Category:** Tricks & Techniques\
**Created:** [March 27, 2026, 6:12am UTC](https://community.silverbullet.md/t/jump-to-random-page-within-a-folder/3991 "2026-03-27T06:12:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jagwarrx](https://community.silverbullet.md/user_avatar/community.silverbullet.md/jagwarrx/32/1659_2.png) [@jagwarrx](https://community.silverbullet.md/u/jagwarrx)\
**Post date:** [March 27, 2026, 6:12am UTC](https://community.silverbullet.md/t/jump-to-random-page-within-a-folder/3991/1 "2026-03-27T06:12:09Z")

</div>

![CleanShot 2026-03-26 at 23.04.03](https://community.silverbullet.md/uploads/default/original/2X/2/22c9c74e0a26640b0f98372e37970e76e4ec4aaa.png)

Pick a top-level folder, land somewhere unexpected. Great for resurfacing dormant notes, rediscovering half-finished ideas, and adding a little serendipity to your SilverBullet workflow.

To activate, paste this command in any page

```space-lua
command.define {
  name = "Navigate: Random Page In Subtree",
  run = function()
    local allPages = space.listPages()

    -- collect unique top-level folders
    local seen = {}
    local prefixes = {}
    for _, p in ipairs(allPages) do
      local top = p.name:match("^([^/]+/)")
      if top and not seen[top] then
        seen[top] = true
        table.insert(prefixes, { name = top })
      end
    end

    local choice = editor.filterBox("Pick a subtree", prefixes, "name")
    if not choice then return end

    -- collect all pages under that folder
    local filtered = {}
    for _, p in ipairs(allPages) do
      if p.name:sub(1, #choice.name) == choice.name then
        table.insert(filtered, p)
      end
    end

    if #filtered > 0 then
      editor.navigate({ page = filtered[math.random(#filtered)].name })
    else
      editor.flashNotification("No pages under " .. choice.name, "error")
    end
  end
}

```

And you can call the command using a button (eg: from home page)

${widgets.commandButton("🎲 Random Page", "Navigate: Random Page In Subtree")}
