Whats a good technique for a random number in C++ ?
Whats a good technique for a random number in C++ ?
The techniques in the FAQ are probably as good as any.
use rand() function along with randomize()
(you need to include time.h for this)
I dont know how effective it is but it is effective..
The following program shows the 20 random nos.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
main()
{
int i;
randomize();
for(i=0; i<20; i++)
{
printf("%d\n", rand());
}
}
hope this helps.
http://mahurshi.tripod.com/mainframes.htm
You can use the "time.h" header file to utilize the system clock to generate random numbers. It's worked for me every time.
MS VC++ 6.0
rand() is not very good for cryptographic applications, and you may need to use a better randomizer (something like L'Ecuyer), but for general purposes it is adequate.