




function random() {
  random.seed = (random.seed * random.a + random.c) % random.m;
  return random.seed / random.m;
}
random.m=714025; random.a=4096; random.c=150889;
random.seed = (new Date()).getTime()%random.m;


function NumToHexString(hexnumber) {
// takes a number as sole argument, returns the hex value. Will make
// the return value at leats two places long by adding zeroes.
// I.e., NumToHexString(10)=="0a".
   var hexstring="";
   var hexchar;
   var hexones;
   var i=0;

   hexnumber=Math.floor(hexnumber);
   while (hexnumber != 0) {
       i++;
       hexones=hexnumber % 16;
       hexnumber -= hexones;
       hexnumber /= 16;

       if (hexones>9) {
	  if (hexones==10) hexchar="a";
	  if (hexones==11) hexchar="b";
	  if (hexones==12) hexchar="c";
	  if (hexones==13) hexchar="d";
	  if (hexones==14) hexchar="e";
	  if (hexones==15) hexchar="f";
       }
       else hexchar=hexones;

      hexstring = hexchar + hexstring;
   }

   for (;i<2;i++) {
      hexstring="0"+hexstring;
   }

   return hexstring;
}

function randomPageColor() {
// Writes the "body" tag to a document (opening tag only)
// including a random background color, and text and link colors
// that should have good contrast against the background color.

   var bg_red=Math.floor(256*Math.random());
   var bg_green=Math.floor(256*Math.random());
   var bg_blue=Math.floor(256*Math.random());
   var text_color;
   var vlink_color;
   var bg_RGB;

   // Here, decide whether the text colors should be light or dark.
   // Rudimentary color analaysis at best; does not try to calculate
   // brightness but estimate it instead.
   if ((bg_red+bg_blue+bg_green)<300 || bg_red < 40
	  || bg_green < 40) {
	       text_color="#ffffff";
	       vlink_color="#cfcfcf";
      }
   else {
               text_color="#000000";
               vlink_color="#303030";
        }

   bg_RGB=NumToHexString(bg_red);
   bg_RGB+=NumToHexString(bg_green);
   bg_RGB+=NumToHexString(bg_blue);

   document.write('<body bgcolor="'+bg_RGB+'"');
   document.write('text="'+text_color+'" ');
   document.write('link="'+text_color+'" ');
   document.write('vlink="'+vlink_color+'">');

   // In case you want to save the body color for future use
   return bg_RGB;
}


var currentRGB = randomPageColor();