>I need to generate two uniform random numbers between 0 and 1 in C ?
Computers do not generate truly random numbers without hardware support.
Some techniques include the detection of radioactive decay and thermal
noise from a reverse-biased diode. There is some belief that there
is randomness in the timing (say, down to picoseconds) of keystrokes,
although I don't think anyone has managed to tie human typing to quantum
effects yet. Some CPU chips have hardware for random number generation
on them.
You may want pseudo-random numbers. In cryptography, random numbers
are very important and the difference between pseudo-random numbers
and real random numbers used in encryption may get you killed as a
spy.
If you try to offer casino gambling games (e.g. craps, blackjack,
roulette, etc.) for real money using pseudo-random numbers, you're
going to lose.
rand() returns the same sequence of numbers each time the program
starts up unless you call srand() with a different seed value from
the last time. Seed values are commonly derived from the time and/or
process ID (but NOT in applications where real random numbers are needed,
like gambling or cryptography: 32 bits of randomness isn't enough, and
a poor seed can cripple a good random number generator).
>How to do it ?
There are better pseudo-random number generators than rand().
These have the disadvantage that they are not included in all C
libraries.
>I looked into rand function where you need to #define RAND_MAX as 1
You do not get to redefine RAND_MAX. Also, the return type of rand()
is int, so don't expect any values where 0 < rand() < 1 . If RAND_MAX
were 1 (not allowed by the standard) all you would get is 0 and 1.
>but will this rand function give me uniformly distributed and unique
numbers ?
Consider using algebra. rand() returns [0, RAND_MAX]. You want
numbers between 0.0 and 1.0 including both endpoints. Or is that just
including 0.0 but not 1.0? Consider what these might give you:
((double)rand() )/RAND_MAX
or
((double)rand() )/(RAND_MAX+1)