Need Help getting random items

Hi everyone! I need your help (I am fully new so excuse me if my question is too silly…)
I am building an app that has to pick 2 random items from a column (i have 3 columns in my table, 1 with the items, and other 2 single value, configured to get Randomly from the first one).
Sometimes the app chooses to pick the same 2 items (that is, the random number generated is the same), and i need 2 different items. I can´t figure out how to avoid the app to choose the same value for both.
Also, i want the full process to rebuild by clicking a button, that is, to remake the single value columns and pick again 2 items, without log out and in again in the app.

Any help would be much appreciated! Thanks for reading me, hope i could explain my issue well. Goodnight everyone

You’re halfway there!

Here’s how I would build it:

  1. Single Value > Random (Returns Thing 1 from list of Things)
  2. Lookup Column > Things (Returns an array of all the Things)
  3. Array > Remove Element Column (Removes Thing 1 from the Things Array)
  4. Single Value > Random (Returns Thing 2 from the Array in Step 3)

Robert_Petitto ! Of course, you´re right as usual !! Clean and simple solution, many thanks mate. Hat off from Spain, and nice day to you all

Hi, sorry to bring up an old topic! But I was curious how to solve the ‘button to rebuild the process’ problem, as described in the original question?

I’ve built up the random single value generator and associated filtered lists, however I’m stuck on trying to get a button that refreshes the random values, i.e. gives a new value for ‘random 1’.

Try adding a button and set the action to ‘Shuffle Order’.

Yep I gave this a go after seeing a similar topic elsewhere, but unfortunately it didn’t do the trick.

It may be because of how I’ve structured the front-end. The ‘questions’ in the screenshot below are 3 random questions from a list of questions. So I need to find a way that randomises the questions when the user clicks on the button (for now, I don’t mind if it repeats one or two when randomising).

Try this. Create a user specific text column in your screen table. Then create a single value column that populates that text value across all rows. Then change your button action to Set Column and have it set the user specific column with a Unique ID.

Whenever you press the button, what it should do is update the user specific column, which will update the single value on all rows. This will cause each row to re-compute, which should re-randomize the random value.

Oh I see, i.e. since the single value column is a computed column of sorts, then that changing should in theory re-computer all the other single values which I use for the questions?

I gave it a go as per the below, is this what you meant? The screen table I’ve been using is a single-row working table, which then populates a separate table once the user submits the form with the submit button (separate to the ‘randomiser’ button). It seems the questions aren’t changing when I get the randomiser button to set the column value of ‘reset text’ to a different unique ID, so maybe I’ve done it incorrectly.

Yes, exactly, that was the theory. Seeing that you are only working with a single row, then I guess the first single value column with a unique ID is unnecessary since you are updating the reset column in that same row.

I don’t think you are doing anything incorrectly. I may just have to play around some more to find a solution. I had done a quick test by changing the value in a template column, and that was causing the random single value columns to change, so I had assumed that any update in a row would cause the random to trigger. I may have assumed wrong.

Another thought off the top of my head would be to create three columns to hold 3 unique ID’s, set those three unique IDs with the button, then create 3 random number generator columns seeded from those unique IDs, then set the single value question columns to pull a value based on each respective random number. A bit messy, but wouldn’t solve the duplicate question problem.

I’m sure there is a much simpler way, and I feel like there is a similar post somewhere in the forum. I’ll have to see if I can find it. At worst, we may need a javascript column to generate 3 unique random numbers or something like that. There’s a solution out there somewhere. I’ll play around later and see what I can come up with.


I appreciate that Jeff, thank you.

I’m wondering if there’s a way to do something like this, and also use an ITE column to identify if there is a duplicate - if so, then it randomises again, and repeats until it lands on something that isn’t a duplicate? Not sure how doable this is, aside from it being a messier solution :slight_smile:

Sorry for the delay. Finally got some free time to work on this.

First of all, Robert had reported to Glide that there is in fact an issue with the Shuffle action, so I’m thinking that will be fixed sometime this week. However, I don’t think that would be a great way to ensure that each of the questions are unique to each other. Because of that, I threw together a quick sample app with javascript to randomize the questions while keeping them unique, so there shouldn’t ever be duplicates when they are reshuffled. Also, instead of a shuffle action, instead I’m still setting a unique ID. That unique ID is passed into the javascript column, but the ID is not used for anything. It’s just there to retrigger the javascript, which will return new random questions.

Copy the app, have a look at it, and see if you have any questions.
If anybody has better code, feel free to share. This was just something I threw together quickly. Essentially it gets a random question from an IN array, adds it to an OUT array, and removes that question from the IN array, so the next random won’t grab a question that’s already been selected.

Side note, if Glide fixes the shuffle issue, then there may be a possible chance that we could eliminate the unique ID and go back to using the shuffle action. Something to keep it mind as it may save on update counts.


Wow thanks Jeff, this looks like it does the job!