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
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.
Hope is the first step on the road to disappointment.
Read the FAQ
There's an answer in there.
http://faq.cprogramming.com/
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
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
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.