Skip to content

Conversation

@mohammad-alisafaee
Copy link

@mohammad-alisafaee mohammad-alisafaee commented Oct 13, 2025

This is a great project! Thank you!

This PR allows moving backward in the random sequence by using a reversible random generator. It adds a Previous Random File action and allows setting keyboard shortcut for it. It replaces the QT random generator with a reversible one. Random navigation algorithm is fairly simple: We keep two arrays sized to the number of files in the folder:

  • permutation[i]: A permutation of [0..N-1] that maps file position i to a random file index.
  • positions[random-index]: Reverse maps a random file index to its position i in the permutation.

To get next/previous random index: Compute i = positions[current-index], then i = (i ± 1) % N, and take permutation[i].
The permutation is reinitialized with a different random seed at application startup or whenever the number of files in the folder changes. Since we use a permutation of 0 through N−1, all images are guaranteed to be visited before the sequence repeats.

Overhead: Two integer arrays of length N. Assuming 32-bit ints, that’s N * 4 * 2 bytes. For 10’000 files ~ 78 KB, which is negligible.

The random generator is put in qvrandom.h/.cpp files.

@mohammad-alisafaee mohammad-alisafaee force-pushed the master branch 8 times, most recently from 872d6cb to ccb4bc2 Compare October 15, 2025 10:52
@alfish2000
Copy link

Isn't that somehow already covered (now?) by using the random sort order?
There I can navigate back and forth in a "static" random order.

@mohammad-alisafaee
Copy link
Author

I’m not sure how the PR merge process works here. This PR has been open for a while and still hasn’t been merged. I need to update my master branch, so I’m going to close this PR to avoid any unintended effects. Please PM me if you’d like me to recreate it and this functionality is still needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants