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 tiddlywiki+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/7ad1fb46-382e-417c-a5a4-6e412274a2e8%40googlegroups.com.

Reply via email to