Java generates a random array of 6 digits

Source: Internet
Author: User
Tags rand
The code is as follows: Copy code

Package com. system. oss. common. util;
/**
* Dynamically generate random character arrays
 * 
* @ Author Su Zhiheng
*/
Public class implements messagecodeuntil
{


/**
* Randomly generate an array of 4 digit characters
     * 
* @ Return rands
*/
Public static char [] generateCheckCode ()
    {
String chars = "0123456789 ";
Char [] rands = new char [4];
For (int I = 0; I <4; I ++)
        {
Int rand = (int) (Math. random () * 10 );
Rands [I] = chars. charAt (rand );
        }
Return rands;
    }


/**
* Randomly generate a 6-digit array
     * 
* @ Return rands
*/
Public static char [] generateCheckPass ()
    {
String chars = "0123456789 ";
Char [] rands = new char [6];
For (int I = 0; I <6; I ++)
        {
Int rand = (int) (Math. random () * 10 );
Rands [I] = chars. charAt (rand );
        }
Return rands;
    }


}

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.