Newsgroups: comp.os.msdos.djgpp From: "Dennis Moran" Subject: Re: random numbers error in DJGPP Message-ID: <01bc0d3a$8782ece0$5e0520ce@d-moran> Date: Sun, 02 Feb 1997 16:49:24 GMT References: <32F44A89 DOT 3142 AT ix DOT netcom DOT com> Lines: 28 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Terence Ramos wrote in article <32F44A89 DOT 3142 AT ix DOT netcom DOT com>... > Hello... > > I have been having trouble to get DJGPP to give me random numbers. I am > using the function rand()... this is how my source looks like > > number = rand() % 100 + 1; > > that should give me a random number from 1 to 100 right? well i keep on > getting the same number which is 1. So i took out the + 1 part and now > i only get 0. whats wrong here? Any help would be appreciated... > > [Terence Ramos ] > [de-bug AT ix DOT netcom DOT com] > > While I haven't started learning C yet (getting a book this afternoon!), in QBasic the RND function returns a number between 0 and 1. So to get a number between 1 and 100, try rand() * 100 + 1 . If rand() is the same as RND then that'll work. -- Dennis Moran (aka Coolio) coolio AT coolio9 DOT com http://www.coolio9.com/