X-Originating-Host: 63.25.175.50 Organization: http://www.remarq.com: The World's Usenet/Discussions Start Here Subject: Re: Random # Lines: 31 From: Dogansmoobs Newsgroups: comp.os.msdos.djgpp Message-ID: <16a95cf0.43f84d7c@usw-ex0104-031.remarq.com> References: Bytes: 1357 X-Wren-Trace: eF57U1JLDEYNGkVRWhBMWkNCTEh7UhFcVlNYURlJSBMRDk0RAksFAQUKFA4A Date: Wed, 14 Jun 2000 17:43:34 -0700 NNTP-Posting-Host: 10.0.2.31 X-Complaints-To: wrenabuse AT remarq DOT com X-Trace: WReNphoon3 961030573 10.0.2.31 (Wed, 14 Jun 2000 17:56:13 PDT) NNTP-Posting-Date: Wed, 14 Jun 2000 17:56:13 PDT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com >How can I get a random number? Running DJGPP on Win95 machine. Thanks. This is part of the C standard library. First, you have to include the stdlib.h header. This has 2 function prototypes that you will need. Also, you will need time.h for the time function. By the way, these are only pseudo-random numbers, but I haven't found that they are that unrandom. So first, you have to give the rand function an initializer, you do this with the srand function. I call srand(time(0)) for this. If you do not do this, then the rand function will produce the same pattern of numbers all the time. Next, to get a random number, simply call rand(). And to get a value that I can actually use, I perform a modulus division on the result. So it looks like this: rand() % number. Hope this helped. There are better random number generators somewhere. I believe that there are some in the AllegrO library, and also you might want to check out the snippets site, they have everything else, there is a good possibility that they will have random numbers. - Dogansmoobs Oh, so a microwave and a monitor are differant?? Excuse me while I clean burrito off my monitor........ * Sent from RemarQ http://www.remarq.com The Internet's Discussion Network * The fastest and easiest way to search and participate in Usenet - Free!