From: s_dolan AT ANTISPAMTHINGYbellsouth DOT net (Sean E. Dolan) Newsgroups: comp.os.msdos.djgpp Subject: Re: Random numbers Message-ID: <39ab84ff.50565729@news1.lig.bellsouth.net> References: <8ngtjq$cn1$1 AT news DOT clinet DOT fi> X-Newsreader: Forte Free Agent 1.11/32.235 Lines: 33 Date: Tue, 29 Aug 2000 10:27:43 GMT NNTP-Posting-Host: 209.214.63.54 X-Trace: news4.atl 967544018 209.214.63.54 (Tue, 29 Aug 2000 06:13:38 EDT) NNTP-Posting-Date: Tue, 29 Aug 2000 06:13:38 EDT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com On Thu, 17 Aug 2000 17:49:13 +0300, "Dotso" wrote: >How can i make a function >that gives a random number in different ranges? >Eg. Rand(Min,Max) >would give a random number between Min and Max. > Here's a C variation: #include #include #include float Randf(float min, float max) { return (float)(rand() / (RAND_MAX / (max - min) + 1) + min); } int main() { int i; srand((unsigned)time(NULL)); for (i=0; i<10 ;i++) printf("%f\n",Randf(-.5, .5)); getch(); return 0; } Sean E. Dolan Kill ANTISPAMTHINGY to reply by email