dimanche 1 novembre 2015

Randomly choosing from an array without repetitions

I'm having trouble trying to figure out how I would go about choosing a phrase from an array randomly, without having multiple phrases appear twice in a row. For example, if I had this list of phrases:

phraseList = {"pig","cow","cat","dog","horse","mouse","giraffe"}

I would pick from them randomly using this:

startPhrase = phraseList[math.random(#phraseList)]

But if I ran that line multiple times, how would I make different phrases appear every time, until it runs out of phrases, while it still being randomized? Is there an easy way to do that?




Aucun commentaire:

Enregistrer un commentaire