From: demandrd AT compusmart DOT ab DOT ca (Demandred) Newsgroups: comp.os.msdos.djgpp Subject: Re: Allegro ex11.c Date: Fri, 13 Feb 1998 00:46:00 GMT Message-ID: <34e39746.1884750@news.compusmart.ab.ca> References: <34DF7294 DOT 21D0 AT home DOT com> NNTP-Posting-Host: remote421.compusmart.ab.ca Lines: 28 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk On Mon, 09 Feb 1998 13:18:12 -0800, Dan was heard to ramble: >i have a question concerning a part of the code from the allegro example >files. it's probably a stupid question but i've looked in my c and c++ >books and i can't find the answer. here's the question, in this small >snippet of the code.. > > hotspot[c] += (random() & 7) - 3; > >what does "random() & 7" do? i'm figuring random() returns a random ># of type int maybe? but i have no idea what the "& 7" does. the & 7 >is the only thing that i need an explenation for. any help would be >much appreciated. Hmmm... random() returns a random (duh) integer that can be pretty huge (0 to MAXINT, IIRC), so I'd guess that the & 7 (bitwise AND with 111b) acts like a % 8 (modulus 8)(??). Why, I don't know... maybe bitwise AND is faster than mod? <-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<- <-The Christian Right is Neither<- <-Sinister Ergo Cogito <- <-http://www.geocities.com/ <- <- SiliconValley/Peaks/9539/ <- <-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-