This was inspired by the kde version of xterm, which allows
each new window to be opened with a random pastel-colored
background.

This program ('rlc' --> random-light-colors)
generates ascii strings of the form 'rgb:hh/hh/hh' which
can be used to open an xterm window like this:

xterm -bg `rlc`

The source is listed below.  I have a few bonehead 'c'
questions, however:

Why does this program compile without including stdio.h ?

Does it matter if the variable declarations come before
or after 'main()'?

Any problems with the style or the logic of the code?

Thanks!
================================

#include<stdlib.h>

int n,r,g,b;    /* red, green, blue */

int
main(void)
{
        srandomdev();           /* generate random bits */
        n = 0x7fff & random();    /* but we need only 15 bits */

        r = (n & 0x1f) | 0xe0;    /* red -- force the top 3 bits to ones */
        n >>= 5;                /* next 5 bits */
        g = (n & 0x1f) | 0xe0;  /* green */
        n >>= 5;                /* next 5 bits */
        b = (n & 0x1f) | 0xe0;  /* blue */

        printf("rgb:%x/%x/%x\n", r, g, b);
}

Reply via email to