Random Tiddler Button

It is nice to have a button in empty story river or on the sidebar, on lick shows a random tiddler. I have such a button in TW-Scripts and Mehregan. The button uses the computer time as seed and its output is deterministic, so it does not generate a real random number, but is very handy for our daily use and has no performance impact.

This solution is pure WikiText, no JavaScript.

\define randomTiddler(filter, label)
<$let seed=<<now XXX>>
      minNum  = 1
      maxNum  = {{{ [subfilter<__filter__>count[]] }}}
      randNum = {{{ [<maxNum>subtract<minNum>multiply<seed>divide[999]add<minNum>round[]]  }}}
<$link to={{{ [subfilter<__filter__>nth<randNum>] :else[subfilter<__filter__>first[]] }}}>$label$</$link>

If we linearly map [0, 999] into [alpha:1, beta:n] where alpha is the first tiddler and beta is the number of tiddlers to be used for random display! from mathematics we have

x in [0, 999] (this will be generated by now macro)
y in [alpha, beta] (this is the numbers we like)

then y= (beta - alpha) / 999 * x + alpha

To give a try


  1. https://groups.google.com/g/tiddlywiki/c/GuQ0EMKfZaM/m/WCo26CxqAwAJ
  2. Using Randomness in TiddlyWiki - Discussion - Talk TW
  3. Scripts in Tiddlywiki — codes, macros, and solutions in TW (credits go to @twMat)

Please add your alternative solution to this thread.


Thanks for the share @Mohammad, love your work.

Not so much and alternative solution but a possible addon/enhancement.

I thought you may be interested to know that when the CD (Compact Disk) players then iPods or early music sites, wanted to randomly shuffle music, they discovered it was not random we wanted, but partially random. For example we don’t want any chance of it randomly playing a song twice, three times or even one or two after the last, etc…

In a future version or a different solution it is worth considering using the random function to select a random tiddler, but only as long as it was not previously selected, say in the last N tiddlers selected - like 100. It should be quite easy to keep a history of N random tiddlers, to test against. Although there are possibly some algorithm’s a little more efficient than others, I could assist, if you want. However I expect this is discussed elsewhere on the internet like with the keywords pseudo random shuffle etc…

It would also be possible to allow the “Reader/Listener”, to rate tiddlers and remove highly rated “tiddlers/tracks” sooner from the “don’t reuses/replay yet list”. But then that would be the “preferences shuffle” but then if you track selection/play time you could play a “have not heard for a while semi-random shuffle” etc…

1 Like

Very nice indea!

Yes please!

I cant give it my full attention to this just now but here is the possible logic.

  • Rather than a link, use a button, to navigate to the random tiddler
  • On button click and navigation to a random tiddler, save the current random tiddler to the end of a “visited list” of tiddlers
    • Add to the random tiddler macro a way to exclude tiddlers in the “visited list” from the possible random tiddlers.
    • When the count of the “visited list” is greater than a pre-set value
      • with each press of the button, remove the first tiddler on the list, so it will no longer be excluded from the possible tiddlers. The shorter the list the sooner that tiddler may come up again.

Additional handling;

  • Rather than a single visited list, you could add tiddlers to multiple lists depending on their rating, unrated, rate 1, rate 2 thru 5 rate lists ( a value on the tiddler)
  • See Tobias’s Rate A macro to rate tiddlers
  • Combining these to form the exclude list
  • However for each nth rated tiddler to be added to its list check how many items are in its rate list and once this is exceeded remove the first item
    • Maintain a different maximum length list for each eg unrated 100, 1 rating 50, 2 ratings 25…
1 Like

@Mohammad, Random Tiddler Button is AWESOME good! :purple_heart: Could you (or another Tiddlywiki guru) advise on how to make it randomly pick a link within a SUBSET of all tiddlers in a wiki, as defined by a title or body pattern-match? – for example, a random tiddler with a name beginning “Unicorn” or containing the word “Documentation”?

(context: i am :hatched_chick: only beginning the first baby-steps of my journey into the Tiddlywiki world, and am in awe of the power the system offers and the friendliness of the TW community! :seedling: … many thanks for any & all advice on how to learn to do this sort of thing … after 20+ years my ZhurnalyWiki personal journal has >8,000 pages – it formerly used the Perl-based “Oddmuse” wiki engine, but alas Oddmuse is fading away and seems to have unfixable issues – the Oddmuse “randomatch” link-feature was extremely valuable to me, and if your Random Tiddler Button can pick from a pattern-matched TW subset it would be such a WONDERFUL win! :unicorn:)

1 Like

Hi @zhurnaly

This is a question of filtering:

<<randomTiddler filter:"[prefix[Unicorn]]" label:"From Unicorn">>


<<randomTiddler filter:"[search:title[Documentation]]" label:"From Documentation Subset">>

I am sure other here will give you good advice. For filtering you may learn from @EricShulman answers in this forum, if you like to have the solution with good explanation and reasons behind it. Also you may find the Grok TiddlyWIki book a nice place to start.

I won’t recommend to study official documentation from tiddlywiki.com right now, but after some practice and when you are on the right track, then official documentation from tiddlywiki.com will be your daily reference and acts like an invaluable reference book.


I’m a bit late but I found that time based randomness doesn’t work well if you refresh quickly the wiki, so in my CuratedVideos wiki I use a custom javascript macro :

exports.name = "r";

exports.params = [];

exports.run = function() {
 return Math.random();

A random url becomes (replace $category$ by any tag):



I build a macro to be able to shorten the filter in url but while it works in the wiki, it doesn’t in the url :confused:

I think I will come back to this in january, this should be possible to do in JS

1 Like

Here is a quick shuffle operator I wrote for the sandbox wiki.

It accepts a list of tiddlers as input and shuffles their order. One could for instance retrieve all the tiddlers with a given tag or prefix, and then shuffle them.

It is important to note that while this is useful in filters used in action-widgets, using them outside of action-widgets will cause the result to change potentially on every key-stroke with the potential for excessive refreshing of the widget tree.


This works very well, thanks a lot @saqimtiaz ! Demos — Q&A and tools for tiddlywiki

1 Like

I use this to shuffle the list of plugins in the sandbox at wiki startup, and then use that shuffled order for the carousel display of plugins.

1 Like