hi i want to generate numbers from 65 to 90 using srand and i dont want a number to be generated twice and put them in an array how can i do that
Printable View
hi i want to generate numbers from 65 to 90 using srand and i dont want a number to be generated twice and put them in an array how can i do that
Read the FAQ. Use an array. Check for duplicates. Use some loops.
Quzah.
Read the FAQ
There's an answer in there.
http://faq.cprogramming.com/
well i couldnt find :( i can generate numbers from 1 to 6 but when i try to generate 65 to 90 it generates 150 140 ... im a beginner :(
http://faq.cprogramming.com/cgi-bin/...&id=1043284385
Scroll down
Read about GetRand
> using srand
srand() seeds the pseudo random sequence, use rand() to deliver each successive number in the pseudo random sequence.
> i dont want a number to be generated twice
Mmm, 65 to 90 - you mean 'A' to 'Z' ?
char buff[26];
for ( i = 0, c = 'A' ; i < 26 ; i++, c++ ) buff[ i ] = c;
Or even
char buff[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
That's the uniqueness bit sorted out.
Now shuffle them to produce a random order.
Do a board search, shuffling arrays was discussed quite recently
You don't generate the numbers using srand. srand seeds rand, giving the rand algorithm a starting value. rand() does the work. Check out this link.
EDIT: Beaten.