0

Using rand(), I'm trying to create an array which generates 32 random numbers each time I run the program. However my program below gives me the same 32 random bits each time. Is there anyway I can get it to generate different 32 bits each time I run the program?

    for(a=0;a<32;a++)
    {
        ran[a]= (rand()%2);
    }
user2359244
  • 37
  • 1
  • 6

1 Answers1

0

You need to set up the random seed each time you run the program to something different to do that. What people do is usually this:

#include <time.h>       /* time */
...
srand (time(NULL));
... 
//Calls to rand();

Then your random seed is different at every start of the program. Check more details about srand here.

XapaJIaMnu
  • 1,408
  • 3
  • 12
  • 28