Hi,
can I shuffle structure data?
For example.
I have 1 structure with 10 questions, and each questions have five answers.
I need to shuffle order of questions, not for answers.
Does possible shuffle structure or arrays?
Thank you.
Hi,
can I shuffle structure data?
For example.
I have 1 structure with 10 questions, and each questions have five answers.
I need to shuffle order of questions, not for answers.
Does possible shuffle structure or arrays?
Thank you.
IDK about shuffling a structure but I’ve used a random number strategy countless times. You create an array of numbers; you pick a random number from 0 to the number of elements -1. You then use the number in that element, not the random number. You then remove the number from the array and repeat until the array of numbers has no elements.
This can be expanded to use that number to build a structure name. So, you use the number from the array to choose questions in the other structure.
You would retrieve the answers in the same way.
This is how I setup my questions, I only used 3 but it should automatically adjust to any number.
No. A structure is an implementation of a dictionary. It has key-value pairing for which the order is not relevant. You cannot access a structure’s child using an index. Instead you need to use the key value, which a text.
A modification to @Keith_1357’s solution and using the same question structure, is to push all the key values into an array, and select one at random, and then store that question into a structure (in this case named theQuestion
) so you can access it outside the event: