Probability question

  1. Store the 40 questions in an array.
  2. Set total=40
  3. Select a random integer in the range of 1 to total
  4. Scan the array and find the nth non-null question.
  5. Set the nth element of the array to null.
  6. Subtract 1 from total.
  7. If you want another question jump to step 3.

As others have said, a Fisher-Yates shuffle is the way to go about this.

Don’t overthink it. It’s just a few lines of code to do it right.
Pseudocode…


-- To shuffle an array a of n elements (indices 0..n-1):
for i from 0 to n−2 do
     j ← random integer such that i ≤ j < n
     exchange a* and a[j]

OK, I guess I need to explain that I’m using Storyline 360. It packages web functions and procedures and doesn’t allow for code tweaking. I read in one of its forums that it doesn’t have the ability to prevent duplicate draws (yet), so I wanted to see how common that possibility would be. As it turns out, way too high.

I have 8 banks of 40 questions dealing with Islamic Finance. The client wants 10 questions from each of the first four banks, and in case the user fails the exam, he is taken to a simpler test, 10 questions from each of the four remaining banks. Each bank covers a particular area of Islamic Finance, and it’s possible the client will want other mixes.

I found one solution online that sets up a boolean variable. Its initial value is “True” for each question, and if the question is selected in the random draw, its value is changed to “False.” If the question is drawn again, it jumps to the next slide. It worked, but the slide can be seen shuffling through several times before a “True” slide is chosen. Can’t have that.

While the “Choose the 10 lowest random numbers” suggestion previously posted would work with Excel, SL doesn’t have that as far as I know. It can generate random numbers, but doesn’t have the equivalent of the SMALL command.

So, at least with one draw per batch, there’s no possibility of a repeat draw.