HTML / JavaScript Dynamic Inline XBM Image Generation

A whopping people have visited this page since tea-time yesterday. Click Reload to see the number magically change.


<HTML>
<HEAD>
<TITLE>Random Hit Count</TITLE>
<SCRIPT>
function setHits() {
RandNum = new randomNumberGenerator();
val = RandNum.next() + ""
val = val.substring (2, 12)
PicSize = "HEIGHT=16 WIDTH=8 ALIGN='absmiddle'>";
Digit = new Array();
Head = "#define count_width 8\n#define count_height 16\nstatic char count_bits[] = {"
Digit[0]=Head+"0xff,0xff,0xff,0xc3,0x99,0x99,0x99,0x99,0x99,0x99,0x99,0x99,0xc3,0xff,0xff,0xff};"
Digit[1]=Head+"0xff,0xff,0xff,0xcf,0xc7,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xc7,0xff,0xff,0xff};"
Digit[2]=Head+"0xff,0xff,0xff,0xc3,0x99,0x9f,0x9f,0xcf,0xe7,0xf3,0xf9,0xf9,0x81,0xff,0xff,0xff};"
Digit[3]=Head+"0xff,0xff,0xff,0xc3,0x99,0x9f,0x9f,0xc7,0x9f,0x9f,0x9f,0x99,0xc3,0xff,0xff,0xff};"
Digit[4]=Head+"0xff,0xff,0xff,0xcf,0xcf,0xc7,0xc7,0xcb,0xcb,0xcd,0x81,0xcf,0x87,0xff,0xff,0xff};"
Digit[5]=Head+"0xff,0xff,0xff,0x81,0xf9,0xf9,0xf9,0xc1,0x9f,0x9f,0x9f,0x99,0xc3,0xff,0xff,0xff};"
Digit[6]=Head+"0xff,0xff,0xff,0xc7,0xf3,0xf9,0xf9,0xc1,0x99,0x99,0x99,0x99,0xc3,0xff,0xff,0xff};"
Digit[7]=Head+"0xff,0xff,0xff,0x81,0x99,0x9f,0x9f,0xcf,0xcf,0xe7,0xe7,0xf3,0xf3,0xff,0xff,0xff};"
Digit[8]=Head+"0xff,0xff,0xff,0xc3,0x99,0x99,0x99,0xc3,0x99,0x99,0x99,0x99,0xc3,0xff,0xff,0xff};"
Digit[9]=Head+"0xff,0xff,0xff,0xc3,0x99,0x99,0x99,0x99,0x83,0x9f,0x9f,0xcf,0xe3,0xff,0xff,0xff};"
for (Count = 0; Count < val.length; Count++) {
dig= val.substring (Count, Count+1)
setDigit (dig, PicSize) 
}
}

function setDigit (Dig, PicSize) {
// this function to overcome a bug
if (Dig=="0") { document.write ("<IMG SRC='JavaScript:Digit[0]'" + PicSize) } else
if (Dig=="1") { document.write ("<IMG SRC='JavaScript:Digit[1]'" + PicSize) } else
if (Dig=="2") { document.write ("<IMG SRC='JavaScript:Digit[2]'" + PicSize) } else
if (Dig=="3") { document.write ("<IMG SRC='JavaScript:Digit[3]'" + PicSize) } else
if (Dig=="4") { document.write ("<IMG SRC='JavaScript:Digit[4]'" + PicSize) } else
if (Dig=="5") { document.write ("<IMG SRC='JavaScript:Digit[5]'" + PicSize) } else
if (Dig=="6") { document.write ("<IMG SRC='JavaScript:Digit[6]'" + PicSize) } else
if (Dig=="7") { document.write ("<IMG SRC='JavaScript:Digit[7]'" + PicSize) } else
if (Dig=="8") { document.write ("<IMG SRC='JavaScript:Digit[8]'" + PicSize) } else
if (Dig=="9") { document.write ("<IMG SRC='JavaScript:Digit[9]'" + PicSize) } 
}

function nextRandomNumber ()  {
var Hi = this.seed / this.Q;
var Lo = this.seed % this.Q;
var Test = this.A * Lo - this.R * Hi;
if (Test > 0)
this.seed = Test
else
this.seed = Test + this.M;
return (this.seed * this.oneOverM);
}

function randomNumberGenerator() {
var D = new Date();
this.seed = 2345678901 + (D.getSeconds() * 0xFFFFFF) + (D.getMinutes() * 0xFFFF);
this.A = 48271;
this.M = 2147483647;
this.Q = this.M / this.A;
this.R = this.M % this.A;
this.oneOverM = 1.0 / this.M;
this.next = nextRandomNumber;
}
</SCRIPT>
</HEAD>
<BODY>
A whopping 
<SCRIPT>setHits();</SCRIPT>
people have visited this page since tea-time yesterday. Click Reload to see the number magically change.
</BODY>
</HTML>

Comments: