www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/09/17:48:44

From: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Allegro ex11.c
Date: Mon, 9 Feb 1998 22:29:35 +0000
Organization: None
Distribution: world
Message-ID: <cdZUzFAPN430Ewyu@talula.demon.co.uk>
References: <34DF7294 DOT 21D0 AT home DOT com>
NNTP-Posting-Host: talula.demon.co.uk
MIME-Version: 1.0
Lines: 18
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019