Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
randomizing print statements w/arrays
#1
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. . .
Reply
#2
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.
Reply
#3
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. . .
Reply
#4
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
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#5
oh okay, the key is SWAP. thanx guyz.
here are 10 types of people, those that understand binary & those that dont. . .
Reply
#6
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.
Reply
#7
Well, seph, that can cause repetitions, and that is not desired in a Quiz.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#8
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
Reply
#9
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.
Reply
#10
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. . .
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)