Random number generation with a twist...
nugget2001
Member Posts: 5
Hi everyone, I need a random number generator that will pick a number randomly, pick another number, and do so a total of 5 times, picking out of a set of 28 numbers. Pretty easy right? So here's the twist: I need to be able guarantee the 5 numbers I chose are different, but when I use it again later in the program, it needs to be able to use those numbers again. I am making a quiz game that presents you with a problem and 5 answers one being correct and linked with the question. My problem is sometimes one of the numbers gets chosen twice, and this is especially problematic when the repeated answer is the correct one. Any idea how to make one of these?
Comments
Hey. I would use a table to control it, and remove the row once it had been selected, thereby preventing it from reoccurring.
So if you have 28 questions and answers in a table, randomly pick a row , copy the row to a new table or store it somewhere, then remove it from your original list.
Hope this makes sense.
So basically you want a random selection of 5 numbers from a set 28.
Yeah !
Ah !
Given these are all text answers (so you don't have to worry about number patterning) I would just do it like this . . . .
Change game.answerA to random (1,6)
Change game.answerB to random (7,11)
Change game.answerC to random (12,17)
Change game.answerD to random (18,22)
Change game.answerE to random (23,28)
The selections will be stored in the above attributes, use them how and when you like.
If one answer needs to be the correct answer (always a good ploy in a quiz ), then the 5 answers cannot be selected randomly, one will need to predetermined.
P.S the table method by @adamhwik is a good one too.
Here's a demo to get you started.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Nice !