Random Number Generator with a Seed


I am generating random numbers by using srand(time(NULL)).
Any idea why it always gives just even random numbers? In my case its giving so. Please help i need odd numbers too.
I need the set of 0s, 1s.
for eg : {1,1,0,0,1,0,0,0,1,1,0}

Best Solution



only one time at the beginning of your program, it "shuffles" the random sequence.

Then call


And it will return a number in the range 0 to RAND_MAX.

If you want only 0 or 1 then you can try with

int n = rand() % 2;


int n = rand() & 0x01;