Mail Archives: djgpp/1998/02/09/17:48:44
Dan writes:
>here's the question, in this small snippet of the code..
>
> hotspot[c] += (random() & 7) - 3;
>
>what does "random() & 7" do?
You can probably guess what random() does (see "info libc al random" for
details). The "& 7" part masks off everything but the bottom three bits,
which limits the number to the range 0..7 (this is the same thing as
writing "% 8", but slightly more efficient). Finally I subtract three to
turn the range into -3..4, which is what I actually wanted for the flame
effect...
--
Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
"Pigs use it for a tambourine" - Frank Zappa
- Raw text -