Mail Archives: djgpp/1997/12/18/01:16:18
Jaster wrote:
>
> I was wondering how to return a random float.. rand() and random() do
> only int's as far as I know.. but I need some random floats...
>
> float i
>
> i = rand()%100 //this gives me an int..
>
> can someone please give me a hand... thanks
#include <stdlib.h>
double my_drand(void)
{
return rand()/(RAND_MAX+1.0)
}
please note that this is a basic C question and as such it is
inappropriate for c.o.m.d. give news:comp.lang.c or
news:comp.lang.c.moderated a try.
--
----------------------------------------------------------------------
A. Sinan Unur
Department of Policy Analysis and Management, College of Human Ecology,
Cornell University, Ithaca, NY 14853, USA
mailto:sinan DOT unur AT cornell DOT edu
http://www.people.cornell.edu/pages/asu1/
- Raw text -