Generate a random N-digit/letter password

Source: Internet
Author: User

Prepared by: Xu jianxiang (netpirate@gmail.com)

Time:

From: http://www.anymobile.org

 

1 package oeg. anymobile. util;
2
3 public class RandomStringUtils
4 {
5 /**
6 * obtain random strings
7 * @ param random
8 * @ param len Length
9 * @ return (int) Random Number
10 */
11 public String getRandomString (int random, int len)
12 {
13 java. util. Random rd = new java. util. Random (random );
14 StringBuffer sb = new StringBuffer ();
15 int rdGet; // obtain a random number.
16 char ch;
17
18 for (int I = 0; I <len; I ++)
19 {
20 rdget = math. Abs (RD. nextint () % 10 + 48; // generate a random number from 48 to 57 (key value of 0-9)
21 // rdget = math. Abs (RD. nextint () % 26 + 97; // generate a random number from 97 to 122 (key value of A-Z)
22 CH = (char) rdget;
23 sb. append (CH );
24}
25
26 return sb. tostring ();
27}
28
29 public static void main (string [] ARGs)
30 {
31 system. Out. println (DAO. getrandomstring (51200000, 6 ));
32}
33}

Apache commons

Http://jakarta.apache.org/commons/lang/

 

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.