# generating random numbers using srand

• 11-24-2006
skyrnnr87
generating random numbers using srand
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
• 11-24-2006
quzah
Read the FAQ. Use an array. Check for duplicates. Use some loops.

Quzah.
• 11-24-2006
Salem
http://faq.cprogramming.com/
• 11-24-2006
skyrnnr87
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 :(
• 11-24-2006
Salem
http://faq.cprogramming.com/cgi-bin/...&id=1043284385
Scroll down

> 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
• 11-24-2006
manutd
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.