delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/12/18/01:16:18

From: "A. Sinan Unur" <sinan DOT unur AT cornell DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Random Floats??
Date: Wed, 17 Dec 1997 19:56:20 -0500
Organization: Cornell University (http://www.cornell.edu/)
Lines: 30
Sender: asu1 AT cornell DOT edu (Verified)
Message-ID: <349874B4.25186118@cornell.edu>
References: <34986772 DOT 6942730 AT news DOT earthlink DOT net>
NNTP-Posting-Host: cu-dialup-0054.cit.cornell.edu
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019