How to randomly generate a list of items from a table?


I am trying to generate a weekly menu populated by items picked at random from a list of dishes. My Dishes table in the database contains the following fields:

  1. Dish name (text: contains the name of the dish)
  2. Dish Tag (list: contains tags like “Breakfast”, “Dinner”, “Lunch”)
  3. Dish Accompaniments (list: contains names of accompaniments like “bread”, “rice”, etc)
  4. Dish Category (list: contains text like “low-fat”, “heavy”, etc)

What I want to do now is create a UI which shows me all the days of the week, with three slots for each day: Breakfast, Lunch, Dinner. When I press a “Generate” button I want the app to fill in dishes in the appropriate categories. In the breakfast slot of each day, I want a dish randomly picked up with the “Breakfast” tag, and the name of the dish to be printed on the slot for that day. Same thing for the next day. I also want this to be unique as far as possible, meaning if the dish is used in a previous day, it should not be repeated unless all the dishes marked as “breakfast” are used up.

Additionally, if the Accompaniments field is not empty, whatever is in that field should appear along with the name of the dish. I’ve been struggling with getting this to work. The data is all in place and I managed to do a form that lets users add dishes. What I can’t seem to manage is pulling the data out of the database!

For special hard-mode points, I’d also like to be able to define categories. So before the user hits Generate, they can toggle on or off specific things like “low-fat” or “heavy” and the system first uses all items with those categories and then uses other categories.

What would be even more amazing is to then let the user edit any of the Breakfast, Lunch or Dinner cells on any of the days of the week, swapping out system-generated items with others in the database, then finally saving the week’s menu.

Any ideas?

What will probably help is the search or filter “sort by random sorting” feature. You could list or search all the available breakfasts, randomly sorted, then fill the week from the first seven items.

So to see if I understood you correctly, I would create a repeating group of 7 columns for Breakfast and then in the first one put in a search for dishes where tag = breakfast, sorted randomly, and then let the repeating group fill automatically?

1 Like