Why no support for random in vanilla TiddlyWiki?

After finishing to read https://tiddlywiki.com/#Filter%20Operators , I’ve realized I can’t recall any operator that can return a random number or a random tiddler. I double checked by searching for “rand” on that page - 0 results. By searching this forum, I have learned that there are plugins that solve both problems: Yaisog Bonegnasher — a non-linear personal web notebook and plugins — docs for plugins by tobibeer . But so far I did not find the reason why there’s no support for randomness in the core. Searching the whole TiddlyWiki documentation doesn’t yield any results either. I am curious about such a design choice.

1 Like

See the TiddlyWiki GitHub repo. There is a long discussion. The short answer is TW refreshes the page with every change and random operator will return a different value each time.

There are many random solutions around as macro, widget, etc.

Thanks @Mohammad. It may be worth quoting my answer to the most recent thread:

It’s worth noting that the stumbling block before has been that these random operators have significant pitfalls that can make them hard to use.

For example, imagine a [all[tiddlers]chooserandom[]] operator that picks a random entry from the input list. Naively, one might expect that the following code would display a random note from my collection:

<$list filter="[all[tiddlers]tag[Note]chooserandom[]]" template="$:/core/ui/ViewTemplate"/>

However, the problem lies in the fact that the filter will, by design, return a different tiddler each time it is evaluated. That means that each time the refresh cycle runs, the filter will be re-evaluated a different tiddler displayed. The user experience would be that typing a character into the search box would cause a different tiddler to be displayed.

You can try out something similar with the following fragment of wikitext. Paste it into a tiddler and then watch as the displayed value changes each time a character is typed in the search box:

<$list filter="[<now '[UTC]YYYY0MM0DD0hh0mm0ssXXX'>]"/>

One solution to the problem of displaying a random tiddler at startup would be to choose the tiddler to be displayed in the startup actions, storing its title in a state tiddler, and then transcluding it where required.

So, for those reasons, I have reservations about adding random operators along the lines suggested. The safest alternative would be to arrange things so that random number generation can only occur as part of action strings, for example by providing an action widget that generates random values in various ways.

3 Likes