# 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> </$let>
\end


Logic
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

# References

4 Likes

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!

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.

• 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! 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 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! â€¦ 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! )

1 Like

This is a question of filtering:

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


or

<<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.

2 Likes

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):

[[$category$]tagging[]count[]subtract[1]multiply<r>round[]]:reduce[[$category$]tagging[]zth<currentTiddler>]+[get[title]]


https://curated-videos.tiddlyhost.com/#%24%3A%2Ftags%2Fmacro%2Frandom.js:%24%3A%2Ftags%2Fmacro%2Frandom.js%20%24%3A%2FRandomTagging

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

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.

3 Likes

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