Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>bB ranged random number code generator</title>
- <script>
- var mv, rg, nm, kf = "!k", jf = "!j", st
- function rnmb(p){return p.replace("!m",mv).replace(/!n/g,nm).replace(/!b/g,"<br>");}
- function ro(p){return p.replace("!o",st);}
- document.write("<pre><div id=\"text\" style=\"height:120px;\"></div><br>");
- document.write("<div id=\"btns\"></div><br>");
- document.write("<div id=\"bB\" style=\"height:20px;\"></div><br><br>");
- document.write("<div id=\"asm\" style=\"height:400px;\"></div></pre>");
- btns.innerHTML = "<input type=\"number\" id=\"minv\" min=\"0\" max=\"254\" value=\"0\" onchange= \"rrf()\"> ";
- btns.innerHTML += "<input type=\"number\" id=\"range\" min=\"2\" max=\"254\" value=\"2\" onchange= \"rrf()\"> ";
- btns.innerHTML+="<input type=\"text\" id=\"vnm\" size=\"16\" value=\"temp1\" onchange= \"rrf()\"> ";
- function rrf(){
- mv = Number(minv.value); rg=Number(range.value); nm=vnm.value
- if (mv+rg>255){rg = 255-mv;range.value=rg;}
- if("!2!4!8!16!32!64!128!".indexOf("!"+rg+"!")==-1){bbf();asmf();}else{p2f();}
- }
- function p2f(){
- var p = rg - 1;
- st = "rand & " + p;
- if (mv){st = ro("(!o) + !m");}
- bB.innerHTML = rnmb(" !n = " + st);
- st = " asm!b jsr randomize!b and #!p!b".replace("!p",p);
- if (mv){st += " clc!b adc #!m!b";}
- st += " sta !n!bend!b";
- asm.innerHTML = rnmb(st).replace("!p",p);
- }
- function bbf(){
- var i=rg,k=256,j=0;
- st="!n/";
- if (i>128){i++}
- while(i>=1){
- if(i&1){
- if(j){
- st=ro("!o!j + !n").replace(jf,i?j:k);
- if(k>2){st=ro("(!o)/");}
- }
- j=1;
- }
- i=i/2&255; j*=2;k/=2;
- }
- bB.innerHTML = rnmb(" !n = rand/2 : !n = " + st + (k>1?k:"")) + (mv?" + "+mv:"");
- }
- function asmf(p){
- var i=rg,k=8;
- var st =" asm!b jsr randomize!b sta !n!b lsr!b";
- while((i&1)==0){i/=2;k--;}
- i/=2;k--;
- while(i>1){
- if (i&1==1){st+=" adc !n!b ror!b";}
- else{st+=" lsr!b";}
- k--;i/=2;
- }
- while(k>0){st+=" lsr!b";k--;}
- if(mv){st+=" clc!b adc #!m!b"}
- asm.innerHTML=rnmb(st + " sta !n!bend!b");
- }
- text.innerHTML += "This script produces bB and asm code to return a range of random numbers<br>"
- text.innerHTML += "The number on the left is the first number in the range<br>"
- text.innerHTML += "The number in the middle is the number of numbers in the range<br>"
- text.innerHTML += "The text on the right is the name of the variable to use<br>"
- text.innerHTML += "So if you specify 5 as the first number and 15 as the range using<br>"
- text.innerHTML += "temp1 as your variable, you'll get numbers 5..14 in temp1 from the code<br>"
- text.innerHTML += "The asm is a little more accurate and has a more even distribution<br>"
- rrf();
- </script>
- </head>
- <body style="background-color:#CCCCC8;font-family:"Arial">
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement