himorogiの日記

主にプログラミングに関することなど。少々ハード(電子工作)についても。

lotos()

<?xml version="1.0" encoding="UTF-8"?>
<Module><ModulePrefs title="hello world example" />
<Content type="html"><![CDATA[
<script type="text/javascript">function lotos(depth){
  var ceil, mask=[0,0], coll =[];

  function getNum(){ return(function(x){ return x.substr(x.length-2,2) })("00"+ Math.ceil(Math.random()*ceil)); };
  isnotUniq= function(x) { return 0!=(mask[Math.floor(x/32)] &  1<<(x%32)); };
  pushNum= function(x) { mask[Math.floor(x/32)] |= 1<<(x%32); coll.push(x); }

  ceil=(function(x){for(i=c=0;i<x; c+= ++i);return c})(depth)*2+1;
  pushNum(getNum());
  while( coll.length<depth ){ pushNum((function(){ while(isnotUniq(x=getNum())); return x; })()); }
  return coll;
};
</script>
miniloto:<script type="text/javascript">document.write(lotos(5).sort())</script>
loto6:<script type="text/javascript">document.write(lotos(6).sort())</script>
]]>
</Content></Module>