Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!lll-crg!nike!ucbcad!zen!cory.Berkeley.EDU!chapman From: chapman@cory.Berkeley.EDU (Brent Chapman) Newsgroups: net.sources Subject: Re: mz.c Message-ID: <823@zen.BERKELEY.EDU> Date: Wed, 5-Nov-86 19:16:32 EST Article-I.D.: zen.823 Posted: Wed Nov 5 19:16:32 1986 Date-Received: Thu, 6-Nov-86 00:50:22 EST References: <4247@ism780c.UUCP> Sender: news@zen.BERKELEY.EDU Reply-To: chapman@cory.Berkeley.EDU.UUCP (Brent Chapman) Organization: UNIXversity of California at Berkeley Lines: 28 Thhis is a neat program, but it assumes that the range of values returned by rand() is 0 to ((2^15) - 1); this is not the case on BSD VAXen and Suns. On those machines (and presumeably others), the code compiles just fine, but sooner or later dies a horrid death when oneof() returns something wierd. The quick, machine independant fix is to mask off all but the low-order 15 bits of the result of rand(). This works, assuming that the low-order bits alone are reasonably random; this may or may not be a valid assumption, depending on your hardware and software. But it's good enough for the purposes of this program. Anyway, the definition of macro oneof() needs to be changed from: #define oneof(n) (int)(((long)(n) * rand())/32768) to: #define oneof(n) (int)(((long)(n) * (rand() & 0x7fff))/32768) This works, and is more portable than the original code (note that I do _not_ say that it is portable, or that doing it this way is a good idea; simply that it is _more_ portable than the original.). Brent -- Brent Chapman chapman@cory.berkeley.edu or ucbvax!cory!chapman