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:
-
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.
-
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.