arraysluashufflefisher-yates-shuffle

Lua: How do I shuffle certain elements in an Array?


If I have a table of 5 strings but I only want to shuffle the second, third, and fourth, how would I go about it?

Question = {“question here”,”resp1”,”resp2”,”resp3”,”answer”}

And I only want to shuffle resp1, resp2, and resp3 in their positions.


Solution

  • You can write

    Question[2],Question[3],Question[4] = Question[3],Question[4],Question[2]
    

    for instance, or any other permutation.