Select a random element when a button is clicked

Hello. I’m just playing around with Grist for the first time. I want to solve a very small use case I was previously using a Google spreadsheet to do.

I have a list of rows, each with two simple string fields (Album and Artist) and I want to select a random one on demand. I’m not sure how to achieve this.

I tried:

  • Add a column with a random value (=RAND()), sort by it, grab the top one. Problem: the random column doesn’t get updated, not even on document reload.
  • Add a view that selects a random field (using Python random.choice on the list of elements) and then shows it. Same problem: it never gets updated after the first (presumably random) choice.

So basically what I’m missing is a way to trigger that random recalculation.

Any pointers on where to look?

Thanks in advance!

I don’t have a custom solution, but I am aware of this custom widget (docs in French) that does random draws based on a number of pulls or a percentage. I played around with it and it works, though there were a few quirks. Might be worth a look!

1 Like

If your formula uses time, even if it just throws the time away (e.g. by reading NOW()) then it would update once an hour. If your formula refers to say a cell in a dummy table, like a Version table with a column of the same name, then every time you change the version number all cells referring to it would be recalculated and you’d get fresh random numbers.

1 Like