I don't think this is a duplicate because I've tried other SO answers and they don't work for me. When I run a program (seeded with time) I get a bunch of random numbers. Then a few seconds later I run the program again and get a similar bunch of random numbers.
srand(time(0));
for(int i=0; i<10; i++) {
cout<<rand()<<"\n";
}
8603 55 3146 26251 14799 16799 28230 314 3602 9504
8639 19984 3044 28803 29955 27225 29699 882 21389 7411
As you can see the numbers are different, but really similar. The reason this won't work for me is because I'm converting it into a float between 0 and 1 (dividing by RAND_MAX). Time in seconds is ticking extremely slowly when I do that. On one run I could have 0.09245...
and next I could have 0.0925...
. I'm using these probabilities to make a blackjack AI, and I don't want the same patterns in betting to show up in subsequent executions.
I've looked many around a lot and tried to put the seed inside the loop, but that just printed the same number 10 times. Not sure how to make the numbers appear completely random from execution time. Thanks for your ideas
EDIT:
Using
srand(rd());
for(int i=0; i<10; i++) {
cout<<generate()<<"\n";
}
14514284786278117030 4620546740167642908 13109570281517897720 17462938647148434322 355488278567739596 7469126240319926998 4635995468481642529 418970542659199878 9604170989252516556 6358044926049913402
I think I get this exact same sequence every time I run it.
EDIT 2:
A little bit of background to clear up confusion. I'd like the distribution to be even but it's ok if it's not it's just my own practice no casino business. My original plan is have 6 characters have a hit/stay probability array for values 12-20. So like Jim would have [0.958367, 0.942123, 0.876655, 0.864322, 0.7543321, 0.653213, 0.201201, 0.12919, 0.00001] Made those numbers up. Let's say Jim had a hand of 14. So I get a random 0-1 number, and if it is less than 0.876655 then he'll hit. Winners after a 100 rounds will have their "genes" mixed and after maybe a 1000 cycles the perfect child will be naturally selected and the perfect hit/pass ratio will be formed. That's how come I noticed Pam or somebody would always hit: their random gen always fell at like 0.05 and so she hit no matter how good or bad her hand. I'm pretty much done, the only thing is fixing this random generator and another small bug dealing with betting money (unrelated I promise)