Re: More efficient ways...
Are you trying to get 1/3 or your numbers to be 9999?
Re: More efficient ways...
No, I can change a few things within the code so that 9999 is not even possible...this code was more of just a "test" to ensure that if any number generated was < 9999 that it set it to 9999 instead of like 10249 or something.
Best was I can explain is imagine a game with min/max values for certain counters (HP, Damage, etc.) So lets say Min Damage was 1 and Max was 9999 but with all calculations were done they actually had a max of 15,000...but based on their level the program will only allow a max of 9999....
Now I can ONLY assume because I haven't test it yet...but I'm hoping later I can change a few things so that like
Code:
int num = min+(rand()%15000);
could look more like
Code:
int num = min+(rand()%variable);
This way the program would have predetermined values of what "variable" would be but in another section. The same could be said for "min" being a set value for certain conditions, etc etc etc.
I hope I explained that in a more coherent manner...
Re: More efficient ways...
rand() used in this way isn't even very good as far as "random" goes, you will see a significantly higher amount of times the lower end of the numbers than the higher end ones.
If you need random numbers in the 0-15000 range, you really need to use something other than the C-lib rand() function.
There's several much better PRNG's in the newer C++ libs. See the <random> header file.