# Need Help getting random items

**URL:** <https://community.glideapps.com/t/need-help-getting-random-items/42750>\
**Category:** Ask for Help\
**Created:** [June 5, 2022, 9:44pm UTC](https://community.glideapps.com/t/need-help-getting-random-items/42750 "2022-06-05T21:44:28Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ypunto](https://avatars.discourse-cdn.com/v4/letter/y/cab0a1/32.png) [@ypunto](https://community.glideapps.com/u/ypunto)\
**Post date:** [June 5, 2022, 9:44pm UTC](https://community.glideapps.com/t/need-help-getting-random-items/42750/1 "2022-06-05T21:44:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Robert\_Petitto](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/robert_petitto/32/25193_2.png) [@Robert\_Petitto](https://community.glideapps.com/u/Robert_Petitto)\
**Post date:** [June 5, 2022, 10:56pm UTC](https://community.glideapps.com/t/need-help-getting-random-items/42750/2 "2022-06-05T22:56:46Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![ypunto](https://avatars.discourse-cdn.com/v4/letter/y/cab0a1/32.png) [@ypunto](https://community.glideapps.com/u/ypunto)\
**Post date:** [June 6, 2022, 1:31pm UTC](https://community.glideapps.com/t/need-help-getting-random-items/42750/3 "2022-06-06T13:31:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rathbala](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/rathbala/32/44552_2.png) [@rathbala](https://community.glideapps.com/u/rathbala)\
**Post date:** [August 24, 2022, 9:25am UTC](https://community.glideapps.com/t/need-help-getting-random-items/42750/4 "2022-08-24T09:25:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [August 24, 2022, 12:03pm UTC](https://community.glideapps.com/t/need-help-getting-random-items/42750/5 "2022-08-24T12:03:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rathbala](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/rathbala/32/44552_2.png) [@rathbala](https://community.glideapps.com/u/rathbala)\
**Post date:** [August 24, 2022, 1:17pm UTC](https://community.glideapps.com/t/need-help-getting-random-items/42750/6 "2022-08-24T13:17:57Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/b/7/b7dacfe002f643698eec16ec9e80dcd3b008afb1.png)

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [August 24, 2022, 1:40pm UTC](https://community.glideapps.com/t/need-help-getting-random-items/42750/7 "2022-08-24T13:40:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rathbala](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/rathbala/32/44552_2.png) [@rathbala](https://community.glideapps.com/u/rathbala)\
**Post date:** [August 24, 2022, 3:27pm UTC](https://community.glideapps.com/t/need-help-getting-random-items/42750/8 "2022-08-24T15:27:14Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/a/1/a1e9b37c1d7252933b6fa1e604a918dd4f62a48f.png)

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [August 24, 2022, 3:57pm UTC](https://community.glideapps.com/t/need-help-getting-random-items/42750/9 "2022-08-24T15:57:20Z")

</div>

> [@rathbala](#):
>
> 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?

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.

---

<div class="post-metadata">

**Author:** ![rathbala](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/rathbala/32/44552_2.png) [@rathbala](https://community.glideapps.com/u/rathbala)\
**Post date:** [August 25, 2022, 6:57am UTC](https://community.glideapps.com/t/need-help-getting-random-items/42750/10 "2022-08-25T06:57:19Z")

</div>

I appreciate that Jeff, thank you.

> [@Jeff\_Hager](#):
>
> 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 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 🙂

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [August 28, 2022, 11:33pm UTC](https://community.glideapps.com/t/need-help-getting-random-items/42750/11 "2022-08-28T23:33:14Z")

</div>

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.

> **[Random Unique Questions](https://random-unique-questi-tb4r.glideapp.io)**

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.

---

<div class="post-metadata">

**Author:** ![rathbala](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/rathbala/32/44552_2.png) [@rathbala](https://community.glideapps.com/u/rathbala)\
**Post date:** [August 30, 2022, 8:22am UTC](https://community.glideapps.com/t/need-help-getting-random-items/42750/12 "2022-08-30T08:22:32Z")

</div>

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