// by situ zhengmei http://www.cnblogs.com/rubylouvre/ var native_random = math. random; math. random = function (Min, Max, exact) {If (arguments. length = 0) {return native_random ();} else if (arguments. length = 1) {max = min; min = 0;} var range = min + (native_random () * (max-min )); return exact = void (0 )? Math. round (range): range. tofixed (exact) ;}; P (math. random () P (math. random (10) P (math. random (3, 10) P (math. random (2, 10, 4)
<Textarea style = "width: 100%" onkeyup = "<br/> This. rows = (function (t) {<br/> for (VAR I = 0, H = 1; I <t. length; I ++) if (T. charat (I) = '\ n') h ++; <br/> return h; <br/>}) (this. value); <br/> "> <br/> var native_random = math. random; <br/> math. random = function (Min, Max, exact) {<br/> If (arguments. length = 0) {<br/> return native_random (); <br/>} else if (arguments. length = 1) {<br/> max = min; <br/> Min = 0; <br/>}< br/> var range = min + (native_random () * (max-min )); <br/> return exact === void (0 )? Math. round (range): range. tofixed (exact); <br/>}; </P> <p> P (math. random () <br/> P (math. random (10) <br/> P (math. random (3,10) <br/> P (math. random (2,10, 4) </P> <p> </textarea>Run Clear
People in the group were bored, so I asked a question about how to use math. Random to implement random numbers. I didn't know at the time. The following function is changed to a C implementation:
// the idea of random mehtodd is taken from // http://ianbullard.squarespace.com/journal/2009/4/28/why-you-should-never-use-rand.html var random = (function () {var high = 1, low = 1 ^ 0x49616e42; var shuffle = function (SEED) {high = seed; Low = seed ^ 0x49616e42;} return function () {var A = new date ()-0 shuffle (a); high = (high> 16); high + = low; low + = high; return high ;}}) (); P (random ()