Qbasicnews.com

Full Version: randomizing print statements w/arrays
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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?
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.
i read that thread before i made this thread. i need a detailed explanation please regarding shuffling string arrays please, thanx. . .
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
oh okay, the key is SWAP. thanx guyz.
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.
Well, seph, that can cause repetitions, and that is not desired in a Quiz.
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
laff.
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
Pages: 1 2