Generating random choices?

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: 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

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

  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.

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?

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.

I attempted creating random links/images in 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.