Computer Science Canada How do you randmomize strings? |
Author: | Wintermini [ Fri Jan 08, 2010 9:44 pm ] | ||
Post subject: | How do you randmomize strings? | ||
Basically, I'm doing a MULTIPLE CHOICE quiz with the following questions, and so far i have this down:
|
Author: | deltamanx [ Fri Jan 08, 2010 9:56 pm ] | ||
Post subject: | Re: How do you randmomize strings? | ||
You could take the long round about way of doing it and do this:
But I don't think you want to do that. |
Author: | Ktomislav [ Sat Jan 09, 2010 11:50 am ] | ||
Post subject: | Re: How do you randmomize strings? | ||
You mean how to make you program asks you a random question? If so then use what deltamanx said or simplified:
num_of_q is number of questions you have got so far. So for now num_of_q is 8. The reason -1 is there is because you started your question array from 0. Hope this helps. |
Author: | Insectoid [ Sat Jan 09, 2010 9:17 pm ] |
Post subject: | RE:How do you randmomize strings? |
The problem with that is that you can have questions repeat. Better to have a 'shuffle' function. There are different ways to do this, the easiest being an array of strings, then select 2 random elements and swap them. Do this X amount of times (I dunno exactly how big X should be, probably array size * another variable. It's hard to judge the point where it can be called 'shuffled'). Shuffling is actually remarkably similar to sorting. |
Author: | Ktomislav [ Sun Jan 10, 2010 5:15 am ] |
Post subject: | Re: How do you randmomize strings? |
If want to make sure your questions don't repeat use array which contains indexes of asked questions. And ofcourse a counter to know how many questions your program has asked so far. Lets say asked: array of int and num_asked: int. So for instance if your program asks question number five num_asked := num_asked + 1; and asked (num_asked) := 5; |