Selecting a random question from a pool of questions until all questions are selected.

1 view (last 30 days)
Hello. I am trying to create a random question generator for a project of mine but I do not know how to program matlab to pull out a question from a pool of questions. I was thinking that one would give values to each question and then have matlab randomly select a value that matches one of the questions but the only thing I know to do is to make matlab randomly output a number. Is there a way to make matlab output a random variable? Thank you!!!!!
  1 Comment
Guillaume
Guillaume on 12 Mar 2015
Is there a way to make matlab output a random variable?
Hopefully, each of your question is not held in its own variable. They are all in a cell array or similar container. In which case, it's a simple matter of using randperm as per James' answer and indexing the cell array.

Sign in to comment.

Answers (1)

James Tursa
James Tursa on 12 Mar 2015
If you have n questions, then
q = randperm(n);
Gives you a random ordering of the numbers 1 through n. You can use that to cycle through the questions randomly and hit every question without repeats.
  5 Comments
Laiza Perez
Laiza Perez on 2 Dec 2020
I know the questions are randomly selected but how do you get the answers to also reorder to match the questions that are reordered?

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!