From: "John M. Aldrich" Newsgroups: comp.os.msdos.djgpp Subject: Re: How to limit a random() with DJGPP ? Date: Fri, 06 Feb 1998 00:15:37 -0500 Organization: Two pounds of chaos and a pinch of salt. Lines: 42 Message-ID: <34DA9C79.428A@cs.com> References: <6bdeu3$evr$1 AT news4 DOT isdnet DOT net> NNTP-Posting-Host: ppp219.cs.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk JCx wrote: > > Hi ! I started coding some kind of game a few days ago, and was surprised by > how easy it was to move from Turbo Pascal to C. Allegro is such a wonderful > piece of code that everything is made easy, even for newcomers. In fact, all > my problems come from DJGPP itself. And the most important one is that I > can't find a way to call a limited random(). Was random(10) or anything else > in Turbo Pascal... what about the same thing with DJGPP ? Thanks to anyone > who could help me ! Basic C math operators: + add - subtract * multiply / divide % modulus (remainder of x / y) To clip any number to a range from 0 to n-1, mod it with n. Therefore: #include #include int main( void ) { int i; srandom( time( NULL ) ); /* seed RNG with system clock */ for ( i = 0; i < 100; i++ ) printf( "%3d ", random( ) % 100 + 1 ); printf( "\n" ); return 0; } It's not exactly rocket science. :-) -- --------------------------------------------------------------------- | John M. Aldrich | "It may be better to be a live jackal| | aka Fighteer I | than a dead lion, but it is better | | mailto:fighteer AT cs DOT com | still to be a live lion." | | http://www.cs.com/fighteer | - Lazarus Long | ---------------------------------------------------------------------