Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!spool.mu.edu!cs.umn.edu!kksys!wd0gol!newave!john From: john@newave.UUCP (John A. Weeks III) Newsgroups: comp.lang.c Subject: Re: random numbers in c Message-ID: <791@newave.UUCP> Date: 28 Apr 91 00:04:26 GMT References: <9104261022.aa28844@Bonnie.ics.uci.edu> Reply-To: john@newave.mn.org (John A. Weeks III) Organization: NeWave Communications Ltd, Eden Prairie, MN Lines: 15 In <9104261022.aa28844@Bonnie.ics.uci.edu> sto@Bonnie.ICS.UCI.EDU writes: > does anyone know how to generate random numbers in c from X to > Y , where X and Y can be postive or negative ? Assuming that you have a procedure that returns random numbers between 0 and 1, try using n = X + ( random() * ( Y - X ) ). You might want to compute the range somewhere else, and then take the absolute value of it (in case X > Y). -john- -- ============================================================================= John A. Weeks III (612) 942-6969 john@newave.mn.org NeWave Communications ...uunet!tcnet!wd0gol!newave!john