I use this code for random numbers, and up until now it seems to work pretty well. :-)
Code:
#include <ctime>
#include <cstdlib>
#include <iostream>
using namespace std;
bool random = true;
int r( int r1 , int r2 )
{
if( random )
{
srand( ( int ) time ( 0 ) );
random = false;
}
int r3 = rand();
return r3 = rand() % ( r2 - r1 + 1 ) + r1;
}
int main()
{
cout << r( 1 , 40 ) << endl;
cout << r( 1 , 40 ) << endl;
cout << r( 1 , 40 ) << endl;
cin.get();
return 0;
}
I'm still a beginner at programming, though, so the code might be a bit crude.
I hope it helps you, though. :-)