Random number generator

I need to generate binary random numbers. But whatever i do the code seems to generate the same random number for every execution. I need the code to generate different random numbers for each run.

i used 3 different methods but none helped

1.cout<< bitset<32>(char( rand() ) ) <<"\n"

2. for(int i=0;i<32;i++)
{
r=rand() %2+0;
r1[i]=(char)((int)'0'+r);

}

3. for(int i=0;i<32;i++)
{
r=rand()/((RAND_MAX+1)/2);
r1[i]=(char)((int)'0'+r);

}

Could someone help me with this?
you need to seed the random number generator.

Call srand once at the start of main:

 
srand( (unsigned)time(0) );
Thanks a lot. That solved the problem
Topic archived. No new replies allowed.