Help with randomizing- please help.

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
Guest

Help with randomizing- please help.

Post by Guest »

I need help with a statistics assignment.
In the program I'm making, I have 25 students.
A student is chosen randomly.
I'll call the one picked first, 1.
1 picks another random number from 1 to 25. Let's say that 1 picks 2.
Now 1 and 2 pick two more random students from the group.
1 picks 3 and 2 picks 4.
So 1, 2, 3, and 4 have been picked. Now, each of those four students gets to pick another student. (randomly from 1 to 25).
On the next round, if 1 picks 4 (a student previously picked), how do I stop 1 from picking more students? Is there a command to stop student 1 from picking more random numbers if the random number generated is equal to a random number generated previously?

Thanks, I'd really appreciate any help on generating random numbers, etc.
MystikShadows
Veteran
Posts: 703
Joined: Sun Nov 14, 2004 7:36 am
Contact:

Post by MystikShadows »

Hi Guest.

There's no command to stop the Random generation however, you can exit the loop with EXIT FOR or EXIT DO depending on the loop method you use. There's no way to know what was generated before unless you work with an array of students...

DIM Students(1 to 25) AS INTEGER

and when your RANDOM generator selects 4 then you set it's array equivalent to say 1

Code: Select all

RandomNumber = INT(RND()) * 25  '  <- whatever parameters you have.

IF Students(RandomNumber) = 0 THEN  ' Not Selected Before
   Students(RandomNumber) = 1
ELSE  ' IF it's already 1 then it means it's been selected already.
    EXIT FOR ' or EXIT DO or whatever loop construct you used.
END IF

Hope this helps
When God created light, so too was born, the first Shadow!

MystikShadows

Need hosting? http://www.jc-hosting.net

Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
Post Reply