Posts: 80
Threads: 11
Joined: Aug 2003
i briefly searched but couldnt find the answer. i am doing a quiz & i want the questions to randomly use the data statements & insert them in print statement. i dont want the code, i want to try to figure this out for the most part but i need some clues on what to use. i know the set up for the print statement but it will only print the last data statement. i thought about RANDOMIZE but it only deals w/numbers. so not sure what else i can use?
here are 10 types of people, those that understand binary & those that dont. . .
Posts: 358
Threads: 15
Joined: May 2003
Perhaps you could put each question into a member of a string array. Then you could shuffle the array and then get your questions by calling each question in order? See the recent advice/program I wrote in this thread:
http://forum.qbasicnews.com/viewtopic.php?t=4012
Ask if you want a more detailed answer.
Posts: 80
Threads: 11
Joined: Aug 2003
i read that thread before i made this thread. i need a detailed explanation please regarding shuffling string arrays please, thanx. . .
here are 10 types of people, those that understand binary & those that dont. . .
Posts: 6,419
Threads: 74
Joined: Mar 2002
To shuffle, just do a number of random swaps. For example, shuffing a 10 integers array:
Code:
DIM a%(9)
FOR i% = 0 TO 9: a%(i%)=i%: NEXT
' Let's shuffle:
FOR i%=1 TO 20 ' Let's do 20 swaps, for example.
SWAP a%(INT (RND*9)), a%(INT (RND*9))
NEXT
' Let's see how they shuffled:
FOR i%=0 TO 9: PRINT a%(i%);:NEXT
Posts: 80
Threads: 11
Joined: Aug 2003
oh okay, the key is SWAP. thanx guyz.
here are 10 types of people, those that understand binary & those that dont. . .
Posts: 1,813
Threads: 284
Joined: Mar 2003
That's not the only way you can do it. The key isn't SWAP, that's just an added extra feature. It works just as well like this:
Code:
RANDOMIZE TIMER
DIM array(3 to 6)
array(3) = "whatever"
array(4) = "boo"
array(5) = "Seph is kickass"
array(6) = "rocking horses"
PRINT array(INT(RND * UBOUND(array)) + LBOUND(array))
The key is RND. If I'm correct, that equation shall work for any array.
earn.
Posts: 6,419
Threads: 74
Joined: Mar 2002
Well, seph, that can cause repetitions, and that is not desired in a Quiz.
Posts: 99
Threads: 20
Joined: Dec 2002
couldn't you create a string of #'s and remove the #'s that are used?
and then using random #'s take another # and have that be the array you take?
BTW i don't know anything about arrays
P.S. :???: :???: :???: at next post
Posts: 3,368
Threads: 195
Joined: Jan 2003
laff.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."
Visit www.neobasic.net to see rubbish in all its finest.
Posts: 80
Threads: 11
Joined: Aug 2003
why not make a new post rather than editing the old one so people can see what you wrote?
Quote:P.S. :???: :???: :???: at next post
here are 10 types of people, those that understand binary & those that dont. . .