Possible Duplicate:
How do I create a random alpha-numeric string in C++?
I need to create a 6 digit number. What should I use? Can someone give me a c++ code example?
This is my code: (once in a while the number is repeating)
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>
using namespace std;
int
main (int argc, char *argv[])
{
/* Simple "srand()" seed: just use "time()" */
unsigned int iseed = (unsigned int)time(NULL);
srand (iseed);
/* Now generate 5 pseudo-random numbers */
int i;
bool da=false;
while (da==false)
{if (rand ()%1000000<=999999)
{cout<<"random nr: "<<rand ()%1000000<<endl;
da=true;
}
else da=false;
}
/* for (i=0; i<5; i++)
{
printf ("rand[%d]= %u\n",
i, rand ());
}*/
return 0;
}
Thx Appreciate