Page 1 of 1

Easy Question I'm sure...

Posted: Sat Dec 13, 2003 2:16 pm
by Guest
Hi there, I was just curious of how to do one little thing.

Let's say I wanted QBASIC to generate random numbers between 1 and 10 and based on that number, it would print out a particular word associated with that number (something I would define,) but then I would want it to do it again, but not including the previous number generated (thus not printing the same word twice if it repeats 10 times.

In case I'm not clear...
if I say that such and such variable = "joe"
and such and such variable = "mary"
and so on with eight other names...
and i want it to randomly select one of them, and then do it until all 8 names are used and none are repeated... how can I do this?

Thanks!

Robbie

Re: Easy Question I'm sure...

Posted: Wed Dec 17, 2003 6:46 am
by Dr_Davenstein
Here ya' go!!!
;D  :D  ;)

Code: Select all

SCREEN 13
RANDOMIZE TIMER

DIM Names$(1 TO 10)

FOR X = 1 TO 10
 READ Names$(X)
NEXT


DO
RandomName = INT(RND * 10) + 1
 IF Names$(RandomName) <> "" THEN
 &nbsp;PRINT Names$(RandomName)
 &nbsp;Names$(RandomName) = ""
 &nbsp;Counted = Counted + 1
 END IF

LOOP UNTIL Counted = 10

DATA Dr_Davenstein,has,taken,the,liberty,to,finish,your,homework,assignment