That's all based on Tobias' random filter. Looking at the code, it appears 
nearly identical Devin's. I suppose there's only so many
ways to wrap that functionality.

I guess one slight improvement would be to pass in context that would 
prevent the number from changing every time the tiddler was refreshed. 
Perhaps use the suffix (as if a field) to indicate "this usage here.". So 
it would be locked in until the browser reloaded.

Note that all random implementations are pseudo random. Supposedly browsers 
now have an api, window.crypto.getRandomValues, that 
produces better random values. I don't know how they can do that -- it's 
like pulling a rabbit out of thin air. The randomness thing only
matters if you're doing things like encrypting critical data, pulling 
numbers for a lottery or doing a research study.



On Tuesday, September 10, 2019 at 10:53:58 AM UTC-7, @TiddlyTweeter wrote:
>
> See 
> https://groups.google.com/forum/#!searchin/tiddlywiki/random$20numbers$20josiah%7Csort:date/tiddlywiki/N263pebgCYI/bWkecUA7AwAJ
>
> On Tuesday, 10 September 2019 19:41:37 UTC+2, Mohammad wrote:
>>
>> Hi TT
>> Is there any filter or math operator to do this?
>>
>>
>> Best wishes
>> Mohammad
>>
>>
>> On Tue, Sep 10, 2019 at 9:51 PM @TiddlyTweeter <tiddly...@assays.tv> 
>> wrote:
>>
>>> One query. DO we need JavaScript for that?
>>>
>>> I thought it was doable in TW already?
>>>
>>> TT
>>>
>>> On Tuesday, 10 September 2019 19:11:51 UTC+2, Mohammad wrote:
>>>>
>>>> One question, 
>>>> How about the performance effects? It seems when a tiddler uses this 
>>>> filter every change on the screen trigger the simple filter!
>>>>
>>>>
>>>> Best wishes
>>>> Mohammad
>>>>
>>>>
>>>> On Tue, Sep 10, 2019 at 12:35 AM Devin Weaver <weave...@gmail.com> 
>>>> wrote:
>>>>
>>>>> For anyone curious here is a neat filter option to grab a random 
>>>>> tiddler from a list:
>>>>>
>>>>> <$list filter="[tag[quote]sample[3]]">
>>>>> <$transclude/>
>>>>> </$list>
>>>>>
>>>>> will show you three random tiddlers with the quote tag.
>>>>>
>>>>> /*\
>>>>> title: $:/filters/sample.js
>>>>> type: application/javascript
>>>>> module-type: filteroperator
>>>>>
>>>>> Filter to return random set from the current list.
>>>>>
>>>>> \*/
>>>>> (function(){
>>>>>
>>>>> /*jslint node: true, browser: true */
>>>>> /*global $tw: false */
>>>>> "use strict";
>>>>>
>>>>> /*
>>>>> Export our filter function
>>>>> */
>>>>> exports.sample = function(source,operator,options) {
>>>>>   var sampleIndex;
>>>>>   var allTitles = [];
>>>>>   var samples = [];
>>>>>   var numberOfSamples = parseInt(operator.operand) || 1;
>>>>>   source(function(tiddler,title) { allTitles.push(title); });
>>>>>   if (numberOfSamples >= allTitles.length) { return allTitles; }
>>>>>   for (var i = 0; i < numberOfSamples; i++) {
>>>>>     sampleIndex = Math.floor(Math.random() * allTitles.length);
>>>>>     samples = samples.concat(allTitles.splice(sampleIndex, 1));
>>>>>   }
>>>>>   return samples;
>>>>> };
>>>>>
>>>>> })();
>>>>>
>>>>>
>>>>> -- 
>>>>> You received this message because you are subscribed to the Google 
>>>>> Groups "TiddlyWiki" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>>> an email to tiddl...@googlegroups.com.
>>>>> To view this discussion on the web visit 
>>>>> https://groups.google.com/d/msgid/tiddlywiki/7ad1fb46-382e-417c-a5a4-6e412274a2e8%40googlegroups.com
>>>>>  
>>>>> <https://groups.google.com/d/msgid/tiddlywiki/7ad1fb46-382e-417c-a5a4-6e412274a2e8%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "TiddlyWiki" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to tiddl...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/tiddlywiki/21677588-663c-40ad-8292-745c5a2f0b18%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/tiddlywiki/21677588-663c-40ad-8292-745c5a2f0b18%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tiddlywiki+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/e8855bed-f449-4438-8bfa-6f5e447bf3c6%40googlegroups.com.

Reply via email to