Mail Archives: djgpp/1998/02/13/03:46:47
On Mon, 09 Feb 1998 13:18:12 -0800, Dan <dyoon AT home DOT com> 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/ <-
<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-
- Raw text -