Question: > 
> **Possible Duplicates:**  
> 
> [How to generate a random number in C?](https://stackoverflow.com/questions/822323/how-to-generate-a-random-number-in-c)  
> 
> [implementation of rand()](https://stackoverflow.com/questions/1167253/implementation-of-rand)  
> 
> [Generating random terrain in Blender3D](https://stackoverflow.com/questions/31834/generating-random-terrain-in-blender3d) 
> 
> 
> 

I need high quality random numbers in C, but I have no idea what to really do. I need to be able to get numbers from 1-100. Any help or maybe point me to where I can find help.

Answer: 
<http://mathworld.wolfram.com/RandomNumber.html>

This article explains the basics to creating your own random number generator that will outperform the standard C library function if you find it lacking in distribution. It produces a better spread and hence a more random number.

This is critical if you hope to produce something that can not be reverse engineered, like for poker sites.
If you really need lottery-quality random numbers, I don't think you want a digital algorithm at all.

[You want an actual physical process. See Random.org.](http://www.random.org/) Are you willing to pay?

Beware programmatic random number generators if you *really* need random numbers. As we've seen in the answers so far, it's not only hard to write a good random(), it's hard to figure out how to use the output from it correctly, whether by modulo or by scaling. Even code that people see as "obvious" often turns out to be subtly incorrect.

Taking the ints into floats or doubles only brings in all the quirks of floating point numbers (such as their ability to represent more numbers close to zero than close to one).

---

What are your requirements? Will your numbers need to be certified? Or do you just *want* really good random numbers? What tests will you employ to see if your random generator is "good?"