# Thread: any function like rand() to ger a randome number of type float?

1. ## any function like rand() to ger a randome number of type float?

hi all

anyone knows whether there is a function like rand() but generates numbers of type float or not?

thanx

2. I don't know of one, but you could write a little function to take the return value from rand() and convert it for you with a simple multiplication and a typecast.

Code:
```int i=rand()%100;
double d=(double)i/10;```

3. ## Yeah

Thats what I would do as well. If you need a decimal there is really no differance than randomizing a whole number then just making it smaller.

4. Code:
```double drand ( void )
{
return ( (double)rand() / (double)RAND_MAX );
}```
-Prelude

5. What the hell ill do ur homework for u

code:

#include <iostream.h>
#include <stdlib.h>
#include <conio.h>

int main ()
{

int number = rand() % 2;

while(!kbhit())
{
for(int y = 0; y < 8; y++)
{
for(int x = 0; x < 8; x++)
{
number = rand() %10;
cout<<number;
}
cout<<" ";
}
cout<<" ";
for(int z = 0; z < 4; z++)
{
number = rand() % 2;
cout<<number;
}
cout<<endl;
}

return 0;
}

There ya go

6. HEHE