obsidian-dataview icon indicating copy to clipboard operation
obsidian-dataview copied to clipboard

Feature srandom - A seeded random number

Open holroy opened this issue 11 months ago • 0 comments

A function generating seeded random numbers, allowing for sorting lists in a random, but predictively fashion.

This function allows for queries to return random items when combined with sorting on the random number, and using LIMIT to get the number of random results you want. Due to the seed, which could be a date like YYYY-MM-DD, the random result will be consistent as long as the source list or the date actually changes.

A simple example query to get three random links:

```dataview
LIST FLATTEN srandom(dateformat(date(today), "yyyy-MM-dd")) as randomValue
SORT randomValue
LIMIT 3
```

I originally hoped to put the expression directly into SORT ... but it requires a field, so it seems I have to use the intermediate FLATTEN ... as randomValue to get it to be that field. But it do work consistently.

holroy avatar Feb 28 '24 17:02 holroy