|
-
Oct 20th, 2001, 03:42 PM
#1
Thread Starter
Hyperactive Member
Non repeating random numbers
I used to do a simple program which randomly picks 10 questions from 20 questions for the user to answer. These 10 questions cannot be repeated.
I programmed in such a way that I kept track of the questions selected and if the same question pops up again, it is discarded and I go on to pick the next random question and repeating the checking again.
There is nothing wrong with my code. But only the first question is random, rand(),(or rather my code,) kept giving me the consecutive numbers.
Eg.
Q17 <-first number is always random.
Q18 <-the rest are not
Q19
Q20
Q1
Q2
Q3
Q4
Q5
Q6
One of my classmates did it this way, he set a random number(ranged between 1 to 1000) to each question , then he sorted them. And he only picked the first 10 of the sorted numbers. And he succeeded.
Can I know how you all do non-repeating random numbers. Anyway that mini project was years ago and was done with.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|