How to generate non-repeating random numbers

This is useful for skills which recites quotes or facts, or manage the flow for music playlists. The numbers can be used to feed API parameters when selecting records from tables via the Integrations block.
.
https://voices.app/?p=1747

Hi

Thanks for this, was useful for helping me think about a similar problem, but was a bit worried about the efficiency when you ran low on “unused” selections.

My plan was to instead:

  1. Create an array with elements 1 to x (where x = total choice space. Say 100 questions.)
  2. Shuffle that array (much like you would a deck of cards)
  3. For each “random” pick take the first item from array
  4. Delete first item from array
  5. Repeat from #3 when array is not empty, else go back to #1

However i’m struggling to actually implement it!

I managed to get this working with some helpful advice from Bill McCarthy in the Facebook community. :grinning:

The one downside of doing it this way is that if you are refreshing your questions regularly, then new additions won’t make it into the rotation for a player until they exhaust the original list from first play. Doesn’t seem like too big a deal unless you are bringing in particularly topical content, but one to bear in mind.