Button to randomize content from a table

I’d like to create a button that every time you click, brings a randomized row from a particular column in a table. I’m able to create the randomized content, but don’t seem to be able to use the button to initiate the next randomized row. Setting the formula to true, updates anytime the page is edited (not helpful). And setting it to false seems to preclude any more randomization. I’d like to randomize every time the button is clicked.

Any help would be appreciated: Disco 1.4.2

:wave: Hey there!

I was going to take a look at it for you but the permission are set so that the document is view only and set so that users cannot copy the document. Can you change either one of those setting so that the community can assist?

Okay, sorry about that. Try now.

Hey there,

Can you check out what I did to the Discos page? Before I give some explanation want to make sure its doing what you are looking for!

Hmmm… not seeing any difference. You updated the Disco Shuffle page?: Disco 1.4.2

Thanks for jumping in here to help, @Scott_Collier-Weir.

Let me link this recent thread for reference. It tackled a similar problem there and also offers some explanations on why Random behaves this way

(whatever you do, please don’t _Delay(300) it :slight_smile: )

Not at my computer at the moment, but essentially what I implemented was the following:

  • Canvas based button that utilized the modifyRows() action to modify a single celled table with a randomItem() from the target table.
  • Created a canvas based formula that referenced the single celled table for display purposes.

What this did was cause every button press to update the single celled table with a random item from the disco table, and then display it for the user above the button.

No need for delay this time @Paul_Danyliuk! :wink: Just a simple combo of modifyRows() and randomItem()

If you wanted it to choose a NEW random item every time the button should modify two columns

  1. Column of single celled table
  2. A checkbox column in the target table to record that it’s already been selected randomly.

Then, have the randomItem() formula choose not from the whole target table but just from the table where checkbox=false

Then, have the button have conditional actions.

  • if(tagretTable.filter(checkbox=false).count=0, modifyrows(targetTable, checkbox, false), random item(targetTable.filter(checkbox=false)))

Again, not at my computer at moment and could throw an example doc together then but the ideas/principles should work

2 Likes

hi @Scott_Collier-Weir can you share your version of the doc?

I am curious how get a function properly at work without _Delay()

Over time I tried many simple solution, in the end they all failed due to limitations as described by @Paul_Danyliuk . An elegant one that still stands is one that makes use of two related buttons and a _Delay(). This I have seen at work in a doc from @joost_mineur

Hey there!

I don’t think the original poster was looking for anything so complex that it would require _delay() or other work-arounds to deal with the limitations of random.

It seems that the original poster just wanted a button click to draw up a random item/row from a table for view. Here is an example document that shows what I believe OP needs:

3 Likes

Generally speaking, the only bulletproof way to generate X random numbers within the same frame (i.e. not having to rely on doc edit to happen in-between) is to utilize a helper table that will have as many rows as there are numbers required.

The sample below shows that. The button ensures that if there are not enough rows, more are generated, and then uses the numbers that update continuously and are row-specific as a random sequence:

Non-repeating items are also possible but for that you’d have to hook up the DB Names into the Random table itself (so that we could introspect on items that are already used)

2 Likes

Hi Scott, yes I think this is exactly the kind of thing I’m looking to adapt. I only have View access and when I copied the doc, it didn’t bring over the Edit page with the data. Could you add me as a user, so I can look at the structure you’ve created? Thanks so much!

CJ

Actually never mind, I think I found the hidden tables… will play around and let you know

1 Like

This worked terrifically, FYI. Thanks so much for the help!

1 Like

Way to focus on the requesters needs and just provide a working solution. Looks perfect.

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.