RandomButton

:placard: Summary Adds a button to quickly jump to a random scene, image, performer, studio, group, tag, or gallery, both on overview and internal entity pages.
:link: Repository https://github.com/stashapp/CommunityScripts/tree/main/plugins/StashRandomButton
:information_source: Source URL https://stashapp.github.io/CommunityScripts/stable/index.yml
:open_book: Install How to install a plugin?

Stash Random Button Plugin

Adds a “Random” button to the Stash UI, letting you instantly jump to a random scene, image, performer, studio, group, tag, or gallery—including random “internal” navigation (e.g. a random scene inside a studio).

Features

  • Adds a “Random” button to the Stash UI navigation bar.
  • Supports random navigation for:
    • Scenes (global and within performer, studio, tag, group)
    • Images (global and within a gallery)
    • Performers (global)
    • Studios (global)
    • Groups (global)
    • Tags (global)
    • Galleries (global)
  • Lightweight, no external dependencies.
  • Uses Stash’s GraphQL API.
  • Simple, robust, and easy to maintain.

Installation

  1. Download the Plugin
    git clone https://github.com/Nightyonlyy/StashRandomButton.git
    
  2. Copy to Stash Plugins Folder
    • Move the StashRandomButton folder to:
      • Windows: %USERPROFILE%\.stash\plugins\
      • Linux/Mac: ~/.stash/plugins/
    • Ensure it contains:
      • random-button.js
      • random-button.yml
      • random_button.css
  3. Reload Plugins
    • In Stash, go to Settings > Plugins and click “Reload Plugins”.
    • The button should appear on those pages.

Usage

Click the “Random” button in the navigation bar to instantly jump to a random item, with behavior depending on your current page:

  • Scenes:

    • On the main scenes page, the button selects a random scene from all scenes in your library.
    • On a performer, studio, tag, or group scenes page, it picks a random scene from within that entity.
    • When viewing a scene’s detail page, clicking “Random” again selects a random scene from all scenes (not just from the previous filter).
  • Groups:

    • On the main groups page, the button picks a random group.
    • Inside a group (group’s scenes page), it selects a random scene from within that group.
  • Galleries & Images:

    • On the main galleries page, the button picks a random gallery.
    • Inside a gallery (gallery’s page), it selects a random image from that gallery.
    • When viewing an individual image (image detail page), the button selects a random image from all images in the database, not just from the current gallery.
  • Performers:

    • On the main performers page, it picks a random performer.
    • Inside a performer’s page (performer’s scenes), it selects a random scene from that performer.
    • When viewing a scene’s detail page, clicking “Random” again picks a random scene from all scenes.
  • Studios:

    • On the main studios page, the button picks a random studio.
    • Inside a studio’s page (studio’s scenes), it selects a random scene from that studio.
    • When viewing a scene’s detail page, clicking “Random” again selects a random scene from all scenes.
  • Tags:

    • On the main tags page, it picks a random tag.
    • Inside a tag’s page (tag’s scenes), it selects a random scene from that tag.
    • When viewing a scene’s detail page, clicking “Random” again picks a random scene from all scenes, regardless of tag.

Tip: The Random button always selects from the full library when you are on a detail (scene or image) page, regardless of how you navigated there.


Requirements

  • Stash version v0.27.2 or higher.

Screenshots

image

Changelog

  • 2.0.1:
    • The Random button now works on scene and image detail pages: when viewing an individual scene or image, clicking “Random” selects a random scene or image from the entire database.
    • Improved context awareness for the Random button on all major Stash entities (scenes, performers, studios, tags, groups, galleries, images).
    • When inside a group, tag, studio, performer, or gallery, the button picks a random scene or image from within that entity.
    • When on a group, tag, studio, performer, or gallery detail page (not listing scenes/images), the Random button selects a random group, tag, studio, performer, or gallery respectively.
    • Updated documentation.
  • 2.0.0: Major upgrade! Now supports random navigation for performers, studios, groups, tags, galleries, and images (global and internal).
  • 1.1.0: Initial public release with support for random scenes.
1 Like

Love stashapp, but I feel like the random is severely limited and would love to work on it or atleast try to identify its issue but I am honestly not a programmer and would really be taking a shot in the dark.

I have over 10k scenes, either with using random page generation by listing all videos or pressing the button I feel like im constantly seeing the same scenes. So much so where I expect to see some scenes. It also seems to focus on newly added scenes for some reason or certain groups perhaps added around the same time.

I understand random is hard to program, maybe I just dont know anything but I feel like the way its done could probably be optimized. Again id love to look myself but dont see it in the repository.

I’ve done some more testing on this. I believe what is happening is the random feature is weighing its sort based on last updated\created. I have been able to confirm this in performers as well. In a pool of 1400+ performers, if you create or add 10 or even 50 performers, the random “sort” feature will place them on the first page in a display of or 25. If they are not placed, it is HIGHLY (about 90% chance) likely they will be within the next 3. Theoretically, if the sort was truly random you would have about a 1.5% to 3.5% percent chance of seeing them on the first page. This is happening almost every time i create a new scene\performer and sort by random.

This indicates to me that random is not random and its calculation is weighing on a metric that inherently creates bias with new content as priority.

I have done some more digging on this as it has become a personal vendetta that is solely holding me back from enjoying this feature.

What I have discovered is that if graphQL has no sort field specified it defaults to Date\ID created in descending order. This confirms why I have been seeing only new content.

I suggest on line 22 update:
let filter = { per_page: 1 };

To:
let filter = { per_page: 1, sort: “random” };
or
let filter = { per_page: 1, sort: “id” , direction: “ASC” };

Line 48 update:

let itemVars = { filter: { per_page: 1, page: randomIndex + 1 } };

to

let itemVars = { filter: { per_page: 1, page: randomIndex + 1, sort: “id”, direction: “ASC” } };

Taking this a step further we could possibly cache the selections to local storage that clears after X amount of time. But that is completely beyond my skilllset

I have deployed a fix locally which seems to do the job. Will continue to evaluate and tweak before pushing a change.

Created PR

PS: Thanks for the thread merge

1 Like

I think an added QOL feature that would make this button truly variety driven would cache selections to a file and clear after X amount of time. True random selection you will possibly see duplicates depending on DB size or however long you are in your DB.

While this is not a massive deal breaker creating logic to tag selections to a file or into the DB that auto clears would be ideal. Again, this is out of my wheelhouse however I will look into it. But if someone reading this is more capable than me could jump in it’d be appreciated.