I'm using the rand() function from the Standard c Library to generate numbers for a Monte Carlo simulation in the range 0 to 1 using:
(double)rand()/RAND_MAX
But I noticed that the result was slightly off. I checked at which value the generated numbers averaged out and it was slightly under the expected 0.5.
I read that rand() is Modulo biased but I’m not using modulo here. Is there a more precise way to generate numbers between 1 and 0?
Edit: I'm fairly new to Prngs so i didn't know that some prngs arent threadsafe. I should have mentioned that i used rand() multithreaded. Regardless, your answers helped me to find a faster and threadsafe rng.
My personal favourite is xoroshiro. It passes most pseudorandomness tests and it's incredibly fast, much faster than rand()
.