Tinderbox Forum

Randomize order of notes

I have a container with about a thousand notes. I want to randomize their order (at present they are in the order they were entered). Is there any way to do this? Thanks for any help.

Ok, there’s no random sort feature. But if you populated a Number-type user attribute with a random number—perhaps with several decimal places, to minimise possible value collisions—you could sort the container on that attribute (perhaps with $SortAlso as ‘Name’ in case two values are the same.

So we may make a stamp like so:

$MyNumber = rand()*$ChildCount(parent);

(by all means make a user Number-type attribute of a different name and substitute appropriately.)

The container we set to sort on “MyNumber” then “Name”. Or, via code:

$Sort = "MyNumber";
$SortAlso = "Name";

But you’ve c.1k notes and don’t want to select/stamp them all the time. So let’s add a stamp to apply to the container (you could use an edict for the container). For this, we’ll leave MyNumber alone and make a user Number-type attribute called ‘RandomSort’ (setting container $Sort to ‘RandomSort’ and not ‘MyNumber’):

var vList(collect(children,$Path));
vList.each(aNote){
   $RandomSort(aNote) = rand()*$ChildCount(parent(aNote));
}

One approach springs to mind:

  1. Populate $MyNumber of each note in the container with a random number. You could do this with a stamp, or by creating a temporary agent.

  2. Sort the container by $MyNumber.

Thanks to both Marks for elegant solutions. Amazing the number of things Tinderbox will do easily – I don’t know any other app that could do this so readily.

2 Likes