Xref: news2.mv.net comp.lang.c:67292 comp.os.msdos.djgpp:3697 From: fmarcos AT jet DOT es (Fernando Marcos) Newsgroups: comp.lang.c,comp.os.msdos.djgpp Subject: Re: Use of random Date: Wed, 08 May 1996 23:11:18 GMT Organization: Servicio IBERNET (Telefonica Transmision de Datos) Lines: 24 Message-ID: <4ms6c2$hev@minerva.ibernet.es> References: <4mikhp$pa5 AT frodo DOT smartlink DOT net> NNTP-Posting-Host: info160.jet.es To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp nmarrone AT smartlink DOT net (Nicholas Marrone) wrote: >program compiles and runs without error, but it gives me #s far larger >than integers when I print out some results. I'm using DJGPP v2. Nicholas: As stated in the DJGPP docs, rand() returns a random number (weird thing, isn't it?) between 0 and RAND_MAX. And RAND_MAX is defined in STDLIB.H as 2147483647... which preciselly is an int. I guess from what you write that you expect something upto 65535, which is the maximum value reachable in a 16 bit environment. But remember, DJGPP is a 32 bit compiler, so integers are 32 bit wide. That results is a maximum capacity of +/-2^31 -1, which is (yaho!) 2147483647, or 0x7FFFFFFF. If you need SHORT (16 bit) numbers, try shifting the rand result by 16: short wops; wops = rand() >> 16; Fernando.