hi all
anyone knows whether there is a function like rand() but generates numbers of type float or not?
thanx
hi all
anyone knows whether there is a function like rand() but generates numbers of type float or not?
thanx
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;
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.
-PreludeCode:double drand ( void ) { return ( (double)rand() / (double)RAND_MAX ); }
My best code is written with the delete key.
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
And the cows moo...
AIM:ProdigyCpp
E-Mail:[email protected]
If you like my avatar plz dont copy it go to:
http://www.dragid.com/
HEHE
And the cows moo...
AIM:ProdigyCpp
E-Mail:[email protected]
If you like my avatar plz dont copy it go to:
http://www.dragid.com/