# Thread: generating random numbers using srand

1. ## 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

2. Read the FAQ. Use an array. Check for duplicates. Use some loops.

Quzah.

http://faq.cprogramming.com/

4. 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

5. 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

6. 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.