Javascript Random Number

Source: Internet
Author: User
Tags shuffle
 // 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 () 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.