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: 
By "fair distribution", I assume you mean that you're not generally satisfied by `rand()`. In this case, you should probably use OS-specific methods that produce cryptographically secure random numbers - `/dev/random` or `/dev/urandom` (depending on your needs) on Unix, and `CryptGenRandom` or `RtlGetRandom` on Win32. On Win32 specifically, if you're using VS2005 or later, you may just use `rand_s`.
You can try something like this:

```
main()
{
  srand(time(0));

  for(int i=0;i<1000;++i)
    printf("%f ", ((float)rand())/RAND_MAX*99+1);

  return 0;
}

```

It's as uniform a distribution as the standard rand() can give.