tbwttihs
Mechanical
- Aug 4, 2003
- 20
firstly, im trying to generate 'random' numbers between zero and 49 (guess what for). currently im using:
time_t t;
srand(unsigned (time(&t)));
int num = (rand() % 49);
but as that stands, the numbers im getting dont seem very random. in fact they seem like theyre just being plucked from a sequential count through 0 - 49. also, its wasting a lot of time in my while loop becuase the same number will be generated lots of times before it changes. what more effective way is there of achieving this?
also, i have a simple array which im putting these numbers into "numbers[6]". for my 6 numbers. what sorta syntax would i need to use to sort it into ascending order using the qsort() function? or failing that, what other simple sort algorithms are there that could be used?
cheers,
craig.
time_t t;
srand(unsigned (time(&t)));
int num = (rand() % 49);
but as that stands, the numbers im getting dont seem very random. in fact they seem like theyre just being plucked from a sequential count through 0 - 49. also, its wasting a lot of time in my while loop becuase the same number will be generated lots of times before it changes. what more effective way is there of achieving this?
also, i have a simple array which im putting these numbers into "numbers[6]". for my 6 numbers. what sorta syntax would i need to use to sort it into ascending order using the qsort() function? or failing that, what other simple sort algorithms are there that could be used?
cheers,
craig.