The psuedo random number generator generates a fixed sequence of numbers for a given seed value.
So if you start with the same seed value for your program, you always get the same sequence. To randomise the seed value, it's often seeded with some component of the current time, as that will change between program runs as in the example above. However, if you want to debug a program that uses random numbers, it's helpful to debug it using the same seed value to make the run deterministic.
srand() sets the seed value
rand() returns the next number in the sequence
rand() returns a value between zero and (2^32) - 1 (or 64 on a 64 bit system). Of you want a value between [0, 1) you need to convert the rand() value to a double in your range.