I've been writing some code that uses the rand() function and I have been noticing that the average number is not right in the middle of the set up slightly below it. This is demonstrated in this code i wrote
the typical output value is around .47, but I was expecting a value of .5. I know this is a pseudo-random number generator so that could be why there is this problem. If so ford anyone know how to make a random number generator more random or how to fix up this existing one.
What is the value of RAND_MAX? If it's very small that could be it. RAND_MAX is only 32767 on Microsoft's compiler. In that case when rand() returns values in the range 0-9999, 10000-19999, 20000-29999 (rand() % 10000) will on average give 5000 but when rand() returns values in the range 30000-32767 (rand() % 10000) will give on 1383,5 average. Because that is much lower it will make the total average value lower. A larger RAND_MAX makes the effects of this problem much smaller.
So i checked and found that RAND_MAX is in fact 32767 which makes sense because I am running a windows machine. Is there a way to increase it because if not i think i will just lower the range.