Investigation: Random -- But Within A Range

212 views
Skip to first unread message

@TiddlyTweeter

unread,
Jul 14, 2017, 6:48:41 AM7/14/17
to tiddl...@googlegroups.com
Ciao tutti

This is an early query to see if anyone can confirm whether what I will need will be possible or not.

If it sounds like it is I can lay out the use case in more detail.

By way of background, I have a project with multiple (external) images. When a visitor comes to the TW online I want them to see ONE randomly selected image presented via a modal.

Important to understand is that this is NOT a randomly selected Tiddler (which a gizmo by Tobias Beer does well already).

Rather, the modal initiation should dynamically create a path to a randomly selected external graphic file that the modal displays (obviously only within the range of what is available). The range for the image to randomly pick is currently "0001" to "4000"---with full-file names like: "fw3022.jpg".  

(My thinking behind this is to NOT burden the TW with 4,000 tiddlers it doesn't need to be a lightweight Lightbox).

I hope this is clear enough.

Please ask me to clarify if it is not.

Many thanks
Josiah

Mark S.

unread,
Jul 14, 2017, 12:27:34 PM7/14/17
to TiddlyWiki
I assume you're thinking of using Tobias' random solution ? His is based on selecting tiddler titles. Haven't tried it, but assuming you could construct a massive filter like:

\define reimage() C:\mypath\fw_$(num)$.jpg
<$list filter="0001 0002 0003 ...etc... 4000 +[random[1]]" variable="num" >
<$image source=<<reimage>>/>
</$list

which could be used to build fw_0001.jpg, fw_0002.jpg, fw_0003.jpg ...

Not sure what the performance would be like with 4000 items, or if the parser would break.

Or if you had a data dictionary with the file names in it, or even just numbers 0-4000 you could used the indexes operator.

Mark

@TiddlyTweeter

unread,
Jul 14, 2017, 12:43:23 PM7/14/17
to TiddlyWiki
Thanks Mark S.

A query, does "<$list filter="0001 0002 0003 ...etc... 4000 +[random[1]]" variable="num" >" mean i'd have to literally enter 4000 numbers? If so, that looks like asking for trouble.

Could it not be calculated from a spawned random?

I wasn't actually thinking of using Tobias' solution because it seemed more focused on Tiddlers that exist. What I need is only random creation of a number between 0001 and 4000 to help create an external file link that is transitory.

Best wishes
Josiah

PMario

unread,
Jul 14, 2017, 2:17:53 PM7/14/17
to tiddl...@googlegroups.com
<$list filter="0 1 2 3 4 +[random[1]]" variable="n1" >
<$list filter="1 2 3 4 5 6 7 8 9 0 +[random[1]]" variable="n2" >
<$list filter="1 2 3 4 5 6 7 8 9 0 +[random[1]]" variable="n3" >
<$list filter="1 2 3 4 5 6 7 8 9 0 +[random[1]]" variable="n4" >
<<n1>><<n2>><<n3>><<n4>>
</$list>
</$list>
</$list>
</$list>

just an idea

PMario

unread,
Jul 14, 2017, 2:20:23 PM7/14/17
to TiddlyWiki
imo better:

\define number()$(n1)$$(n2)$$(n3)$$(n4)$

<$list filter="0 1 2 3 4 +[random[1]]" variable="n1" >
<$list filter="1 2 3 4 5 6 7 8 9 0 +[random[1]]" variable="n2" >
<$list filter="1 2 3 4 5 6 7 8 9 0 +[random[1]]" variable="n3" >
<$list filter="1 2 3 4 5 6 7 8 9 0 +[random[1]]" variable="n4" >
<<number>>
</$list>
</$list>
</$list>
</$list>

@TiddlyTweeter

unread,
Jul 14, 2017, 2:33:15 PM7/14/17
to TiddlyWiki
Thanks PMario

I can see what that is doing and it makes sense & should run fast.

I will play with it and see if I can get it to work for what I need.

Best wishes
Josiah

Mark S.

unread,
Jul 14, 2017, 4:03:14 PM7/14/17
to TiddlyWiki
D'oh! Very clever Pmario!

That will actually make a number between 0000 and 4999. Perhaps a number between 0000 and 3999 would be acceptable? That's actually 4000 distinct numbers.

Mark

@TiddlyTweeter

unread,
Jul 14, 2017, 4:29:29 PM7/14/17
to TiddlyWiki
Thanks Mark S.

Yes 0000 to 3999 would work best. I can rename 4000 as 0000. Anything over 4000 would hit a void.

How should PMario's idea be modified for that?

Best wishes
Josiah

Mark S.

unread,
Jul 14, 2017, 4:34:31 PM7/14/17
to TiddlyWiki
Just change

<$list filter="0 1 2 3 4 +[random[1]]" variable="n1" >

to

<$list filter="0 1 2 3 +[random[1]]" variable="n1" >

@TiddlyTweeter

unread,
Jul 14, 2017, 5:21:57 PM7/14/17
to TiddlyWiki
Thank you Mark S. I appreciate it.

Jed Carty

unread,
Jul 15, 2017, 7:46:43 AM7/15/17
to TiddlyWiki
While for this use I think that Mario's answer is better I did make a widget that returns a random number in a given range. http://inmysocks.tiddlyspot.com/#RandVal%20Plugin

Thomas Elmiger

unread,
Jul 15, 2017, 9:55:32 AM7/15/17
to TiddlyWiki
Same here, but different ;–)

I added a random integer generator to my rpn script. No leading zeros though.
<<rpn a:1 b:4000 precision:"r">>
would return a number between 1 and 4000 (including 1 and 4000).

In case anyone wants to try it: https://tid.li/tw5/plugins.html – it is a plugin now.

Happy randomizing
Thomas

Mark S.

unread,
Jul 15, 2017, 10:03:57 AM7/15/17
to TiddlyWiki


We've got at least 3 third-party solutions for finding randoms. Shouldn't something like this be in the stock TW5 filter operator and/or widget tool kit?

Mark

@TiddlyTweeter

unread,
Jul 15, 2017, 3:14:43 PM7/15/17
to TiddlyWiki
Ciao Jed

Thank you for the link. I think Mario or Thomas' solutions will be more economical for the specific need.

BUT, yet again, I end up feeling like a bad dog for not knowing your gizmo existed.

We need do something to sort out our informational mess.
Where stuff exists but we have to rely on the author to tell us what they already publicly published.

Best wishes
Josiah

Jed Carty wrote:
... I did make a widget that returns a random number in a given range. http://inmysocks.tiddlyspot.com/#RandVal%20Plugin

@TiddlyTweeter

unread,
Jul 15, 2017, 3:18:38 PM7/15/17
to TiddlyWiki
Ciao Thomas

That's neat! Between your & PMario's offerings I'm sure I can now move on one way or another. So thanks!

Best wishes
Josiah

Thomas Elmiger wrote:
I added a random integer generator to my rpn script. No leading zeros though. would return a number between 1 and 4000 (including 1 and 4000).


In case anyone wants to try it: https://tid.li/tw5/plugins.html – it is a plugin now.

@TiddlyTweeter

unread,
Jul 15, 2017, 3:25:56 PM7/15/17
to TiddlyWiki
Ciao Mark S.

I agree with you.

I also want to add its an instance of the Informational Chaos we are confronted with here over finding great things people have already created you can't find without a PhD in Searchology.

The de-centralisation of TW has not, unfortunately, yet been properly complemented with appropriate aggregation. On THIS issue I would probably ADORE a centralised server for plugins. Lets get on with it.

Best wishes
Josiah

Thomas Elmiger

unread,
Jul 15, 2017, 4:22:37 PM7/15/17
to TiddlyWiki
Via TW Community Search I found another interesting solution:
http://erwanm.github.io/tw-community-search/ =>

http://let.tiddlyspot.com/#RANDOM:GettingStarted%20RANDOM

Let, by Tobias Beer, selects random tiddlers via filters. (You could find Jed’s solution there too. Mine is brand new so we will have to wait a bit.)

Maybe we should promote Erwan’s great search a bit more.

@TiddlyTweeter

unread,
Jul 15, 2017, 5:56:54 PM7/15/17
to TiddlyWiki
Ciao Thomas

That is a good example of the issue.

I agree that Erwan's tool is there, though underused. I don't use its search much because the people who make things don't signal to it enough to have the heft needed to bother. But its a Working Aggregator and if it were used more it would solve half the problems IMO.

Josiah
Reply all
Reply to author
Forward
0 new messages