Randomly generated keys

Source: Internet
Author: User

Do project to use this thing, so Baidu its method, record it. Code to serve.
Randomly generate n-bit numbers:

function randomnum (n) {     //N is the number of digits generated by    var t= ';       for (var i=0;i<n;i++) {         T+=math.floor (math.random () *10);         }      return t;     }     Alert (Randomnum (6));

Randomly generate N-letters

function getrandomstring (len) {      var//  default removes easily confusing characters ooll,9gq,vv,uu,i1       var maxpos = chars.length;       var pwd = ';        for (i = 0; i < len; i++) {          + = Chars.charat (Math.floor (Math.random () * maxpos))              ;      } return pwd;  }      Alert (getrandomstring (3));

Chars.charat is the character that selects the number of index numbers. Math.floor () rounding down Math.random () takes 0-1 random numbers

The climax comes, the letters plus the digital stitching is

var pwd = getrandomstring (3); var t = randomnum (6); var fdnm = pwd + t;

Randomly generated keys

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.