Happy New Year!
Wish you a very happy and prosperous new year!
I was at my friend’s place yesterday for new year celebrations and we needed a random number generator to play bingo. Instead of writing numbers on chits and picking them up, I hacked together a random number generator using Javascript in about 15 minutes, which looked like this:
I used a simple hash to see that numbers did not repeat and It actually worked pretty well. I was delighted at Javascript’s utility at non geek parties!
Here is the code:
<!-- Devadutta Ghat, last piece of code written in 2008 ;) --> <html> <head> <title>Bingo Baby!</title> <script type="text/javascript"> var gblHash=new Array(); function getNewRand() { return (Math.floor(Math.random()*99)+1); } function getRand() { var ilm=getNewRand(); var i=0; while(gblHash[ilm]==1) { i++; ilm=getNewRand(); if(i>=100) { alert("All numbers done!"); return; } } gblHash[ilm]=1; document.getElementById('randomNumber').innerHTML=ilm; document.getElementById('drawnNumbers').innerHTML +=(" "+ilm); } </script> </head> <body> <div id="randomNumber" style="font-size: 150pt;">-1</div> <input type="button" onClick="getRand();" value="Clicky!"> <div id="drawnNumbers"></div> </body> </html>
And here is a demo
Enjoy 2009!







