Guest User

ranged rand generator

a guest
Sep 20th, 2016
332
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2. <head>
  3. <title>bB ranged random number code generator</title>
  4.  
  5. <script>
  6. var mv, rg, nm, kf = "!k", jf = "!j", st
  7.  
  8. function rnmb(p){return p.replace("!m",mv).replace(/!n/g,nm).replace(/!b/g,"<br>");}
  9. function ro(p){return p.replace("!o",st);}
  10.  
  11. document.write("<pre><div id=\"text\" style=\"height:120px;\"></div><br>");
  12. document.write("<div id=\"btns\"></div><br>");
  13. document.write("<div id=\"bB\" style=\"height:20px;\"></div><br><br>");
  14. document.write("<div id=\"asm\" style=\"height:400px;\"></div></pre>");
  15.  
  16. btns.innerHTML = "<input type=\"number\" id=\"minv\" min=\"0\" max=\"254\" value=\"0\" onchange= \"rrf()\"> ";
  17. btns.innerHTML += "<input type=\"number\" id=\"range\" min=\"2\" max=\"254\" value=\"2\" onchange= \"rrf()\"> ";
  18. btns.innerHTML+="<input type=\"text\" id=\"vnm\" size=\"16\" value=\"temp1\" onchange= \"rrf()\"> ";
  19.  
  20. function rrf(){
  21. mv = Number(minv.value); rg=Number(range.value); nm=vnm.value
  22. if (mv+rg>255){rg = 255-mv;range.value=rg;}
  23. if("!2!4!8!16!32!64!128!".indexOf("!"+rg+"!")==-1){bbf();asmf();}else{p2f();}
  24. }
  25.  
  26. function p2f(){
  27. var p = rg - 1;
  28. st = "rand & " + p;
  29. if (mv){st = ro("(!o) + !m");}
  30. bB.innerHTML = rnmb(" !n = " + st);
  31. st = " asm!b jsr randomize!b and #!p!b".replace("!p",p);
  32. if (mv){st += " clc!b adc #!m!b";}
  33. st += " sta !n!bend!b";
  34. asm.innerHTML = rnmb(st).replace("!p",p);
  35. }
  36.  
  37.  
  38. function bbf(){
  39. var i=rg,k=256,j=0;
  40. st="!n/";
  41. if (i>128){i++}
  42. while(i>=1){
  43.  
  44. if(i&1){
  45. if(j){
  46. st=ro("!o!j + !n").replace(jf,i?j:k);
  47. if(k>2){st=ro("(!o)/");}
  48. }
  49. j=1;
  50. }
  51. i=i/2&255; j*=2;k/=2;
  52. }
  53. bB.innerHTML = rnmb(" !n = rand/2 : !n = " + st + (k>1?k:"")) + (mv?" + "+mv:"");
  54. }
  55. function asmf(p){
  56. var i=rg,k=8;
  57. var st =" asm!b jsr randomize!b sta !n!b lsr!b";
  58.  
  59. while((i&1)==0){i/=2;k--;}
  60. i/=2;k--;
  61. while(i>1){
  62. if (i&1==1){st+=" adc !n!b ror!b";}
  63. else{st+=" lsr!b";}
  64. k--;i/=2;
  65. }
  66. while(k>0){st+=" lsr!b";k--;}
  67. if(mv){st+=" clc!b adc #!m!b"}
  68. asm.innerHTML=rnmb(st + " sta !n!bend!b");
  69. }
  70.  
  71. text.innerHTML += "This script produces bB and asm code to return a range of random numbers<br>"
  72. text.innerHTML += "The number on the left is the first number in the range<br>"
  73. text.innerHTML += "The number in the middle is the number of numbers in the range<br>"
  74. text.innerHTML += "The text on the right is the name of the variable to use<br>"
  75. text.innerHTML += "So if you specify 5 as the first number and 15 as the range using<br>"
  76. text.innerHTML += "temp1 as your variable, you'll get numbers 5..14 in temp1 from the code<br>"
  77. text.innerHTML += "The asm is a little more accurate and has a more even distribution<br>"
  78.  
  79. rrf();
  80.  
  81. </script>
  82. </head>
  83. <body style="background-color:#CCCCC8;font-family:"Arial">
  84. </body>
  85. </html>
RAW Paste Data