## Problem:

How do I generate random float numbers between 0 to 1 in C++?

0 votes

Here you go

`float r = static_cast <float> (rand()) / static_cast <float> (RAND_MAX);`

You may use the **rand()** function

```
double randMToN(double M, double N)
{
return M + (rand() / ( RAND_MAX / (N-M) ) ) ;
}
```

This will generate a random number in the range from `[M,N) (Considering M=0 and N=1).`