even with the use of srand the seeding is only down to the second, really to be truly random you need to write your own but this would beyond the scope of most of us.
For those of you who want to disagree with me do this simple test:
cut copy paste this into a file and run in console: (check code first tho, cause i'm going off the top of my head)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
#include <cstdlib>
using std::rand;
using std::srand;
#include <ctime>
using std::time;
#include <iostream>
using namespace std;
int main()
{
int randInt, count =0 ;
// seed random numbers using time;
srand(time(NULL));
while (i<2)
{
randInt = 1 + rand() % 50;
cout << randInt < endl;
count++;
}
return 0;
}
|
now if you run this once, it will produce 2 completely different numbers between 1 and 50.
run this program again a few seconds later and will produce 2 completely different numbers again.
BUT IF YOU SPAM the up arrow and the enter key on command line, it will run the program multiple times within 1 sec and give you the same numbers for each time the program is run within 1 second.
So knowing this, you need to adjust your code accordingly.
EDIT: so this is why you are seeing HHHHHH,MMMMMMMMM,HHHHHHHHH,HHHHHHHH,HHHHHHH,MMMMMMM,HHHHHHHH etc
however, using my while loop even though you will see the same numbers over and over the 2 numbers within the while loop will be different. So you can easily use srand to achieve your goals, you simply need to understand how the seeding works for you to be able to use it to your advantage.