// // Javascript library containing the "svUnits" unit conversion widget // basic die rolling functions // v1.0 - 8/28/09 // // Based on javascript code copyright 1999 by Scott Virtes // Widget code copyright 2009 by Scott Virtes // var debug=0; var SVROLLER_SID = 3; var MAX_ROLLS = 20; // these variables can be set by user before calling this library // but if not, here are the defaults: if (typeof(svRoller_top_blurb) == 'undefined') svRoller_top_blurb="Let's roll some dice!"; if (typeof(svRoller_main_bg) == 'undefined') svRoller_main_bg="white"; if (typeof(svRoller_main_text) == 'undefined') svRoller_main_text="navy"; if (typeof(svRoller_main_border) == 'undefined') svRoller_main_border="1px solid blue"; if (typeof(svRoller_top_bg) == 'undefined') svRoller_top_bg="navy"; if (typeof(svRoller_top_text) == 'undefined') svRoller_top_text="white"; if (typeof(svRoller_top_border) == 'undefined') svRoller_top_border="0px"; if (typeof(svRoller_result_bg) == 'undefined') svRoller_result_bg="#eeeeee"; if (typeof(svRoller_result_text) == 'undefined') svRoller_result_text="black"; if (typeof(svRoller_result_border) == 'undefined') svRoller_result_border="0px"; if (typeof(svRoller_ctrl_bg) == 'undefined') svRoller_ctrl_bg="#dddddd"; if (typeof(svRoller_ctrl_text) == 'undefined') svRoller_ctrl_text="black"; if (typeof(svRoller_ctrl_border) == 'undefined') svRoller_ctrl_border="1px solid gray"; 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 randomNumberGen() { var D = new Date(); this.seed = 2345679081 + (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; } function rollOne(sides) { // roll = Math.round(Rand.next() * sides) + 1; rnd = Rand.next(); roll = Math.round(rnd * 11111) % sides + 1; // alert( rnd + "=" + roll ); return roll; } function rollMany(count, sides, modifier, multiplier) { msg = ""; total = modifier; for (i=0; iMAX_ROLLS){ alert("The maximum number of rolls is "+MAX_ROLLS+"."); rolls=MAX_ROLLS; } count = 0; hits = 0; result = ""; for (ii=0; ii0) { if (x>=hit) { msg = x + " (Success!)"; hits++; } } if (result>"") result +="\n"; result += msg; count++; if (count>MAX_ROLLS) break; } // if (hit>0) { msg = "\n\n" + hits + " successful rolls"; result += msg; } frm.txtResults.value = result; } // write all our style stuff here: document.write(""); // write all our startup HTML here: document.write("
\n" + "
" + "\n" + "\n" + "\n" + ""); var svRoller_about = "About svRoller\n"; // this row has our controls document.write("\n" + "" ); document.write("\n" + "
svRoller"+svRoller_top_blurb+"
" + "" + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + "
Type of dice:" + " " + " d " + " + " + "
Presets:" + " " + " " + " " + "
Multiplier:" + " (optional)" + "
Success:" + " (optional)" + "
Number of rolls:" + " " + " " + "
" + "
\n" + "
" + "Results:
" + "" + "
" + svRoller_about + "
\n" + "
\n
\n
\n"); Rand = new randomNumberGen();