# Generating random choices?

**URL:** <https://community.glideapps.com/t/generating-random-choices/2677>\
**Category:** Ask for Help\
**Created:** [December 6, 2019, 5:31pm UTC](https://community.glideapps.com/t/generating-random-choices/2677 "2019-12-06T17:31:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sandy\_Ressler](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/sandy_ressler/32/2054_2.png) [@Sandy\_Ressler](https://community.glideapps.com/u/Sandy_Ressler)\
**Post date:** [December 6, 2019, 5:31pm UTC](https://community.glideapps.com/t/generating-random-choices/2677/1 "2019-12-06T17:31:00Z")

</div>

I have a script in a spreadsheet:  
function chooseIt() {  
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();  
var firstSheet = spreadsheet.getSheets()[0];  
var secondSheet = spreadsheet.getSheets()[1];  
var randChoice = 2+(Math.floor(Math.random()\*8));

var myRange = firstSheet.getRange(randChoice,1);  
var choice = myRange.getValue();  
var myImage = firstSheet.getRange(randChoice,3);  
var myImageData = myImage.getValue();

secondSheet.getRange(2,1).setValue(choice);  
secondSheet.getRange(2,3).setValue(myImageData);

}

It in the spreadsheet: [WheresLunch - Google Sheets](https://docs.google.com/spreadsheets/d/1IFfIDlOHtZ39nz7ullP6tpcHz9RFvto_QuvqNNelweY/edit?usp=sharing)

and the “chooseIt” tab only works occasionally the script is not executed always upon selecting the chooseit button  
Link to app: [https://daaiz.glideapp.io](https://daaiz.glideapp.io)

any clues how to get the spreadsheet script to always run…OR how to generate a random number in the app…thanks…Sandy

---

<div class="post-metadata">

**Author:** ![George\_B](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/george_b/32/534_2.png) [@George\_B](https://community.glideapps.com/u/George_B)\
**Post date:** [December 6, 2019, 7:02pm UTC](https://community.glideapps.com/t/generating-random-choices/2677/2 "2019-12-06T19:02:12Z")

</div>

1. There can be up to a 2 min delay in when you make a change in the Glide app and when that information is saved back to the sheet.

2. When on the spreadsheet an selecting the Scripts/Chooseit menu item I think the reason that it doesn’t seem to fire in some cases is that there is a limited number of random numbers being generated, so sometimes the same random number is being generated on the next click.

3. I’m guessing that the whole point is to give the user a random selection when they choose that icon. If the sheet is not open in a browser and you or someone else has run the function that “random” selection is not going to change.

---

<div class="post-metadata">

**Author:** ![Sandy\_Ressler](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/sandy_ressler/32/2054_2.png) [@Sandy\_Ressler](https://community.glideapps.com/u/Sandy_Ressler)\
**Post date:** [December 6, 2019, 7:26pm UTC](https://community.glideapps.com/t/generating-random-choices/2677/3 "2019-12-06T19:26:44Z")

</div>

Yeah correct that the whole point is to give the user a random choice from among all available restaurants (the choices)…is there any local (i.e. on the phone or in app) computation possible?

---

<div class="post-metadata">

**Author:** ![George\_B](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/george_b/32/534_2.png) [@George\_B](https://community.glideapps.com/u/George_B)\
**Post date:** [December 7, 2019, 12:39pm UTC](https://community.glideapps.com/t/generating-random-choices/2677/4 "2019-12-07T12:39:09Z")

</div>

No way to do it within Glides with the current feature set.

If I may make a suggestion. Instead of just a random pic of the computer, from a user standpoint I think it would be more beneficial if they could, drill down so to speak based on type or cost. I’m sure your plan is to add some more information about the restaurants like type (Italian, Asian, etc.) and average costs per meal, maybe using $$$$ to indicate. Then you could add tabs for those categories and sort by those things.

---

<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:** [December 8, 2019, 5:23pm UTC](https://community.glideapps.com/t/generating-random-choices/2677/5 "2019-12-08T17:23:50Z")

</div>

I attempted creating random links/images in [https://concepts.glideapp.io/](https://concepts.glideapp.io/) . The results were mediocre at best. Instead of a script I’m using the RANDBETWEEN. It works, but only regenerates the link on either some schedule I haven’t taken the time to figure out yet or whenever a change is inputted into the sheet. If something changes on the sheet then the link changes, but sometimes the result in the app doesn’t match what’s in the sheet. It’s weird, but kinda works. I was hoping to get it to change every minute to use for affiliate advertising links. Your script is probably a better option and it can be ran on a timed trigger. Just taking a look at your app, I do see the random restaurant changing, so I assume you have something figured out already.
