Java Foundation Basics Summary-----Random number (generates four random numbers)

Source: Internet
Author: User

Foreword: In the development time often will meet, some verification code login, actually these things, very simple. I have developed a Verification code login page, then used the plugin. However, as a qualified developer, to understand the core knowledge of its internal, some things can not be in-depth understanding, but to do at least understand. Whether it's generating a random number, or more, or a letter plus a number or character, this code can be expanded. Code:
1  PackageCom.day13.math;2 3 ImportJava.util.Random;4 5 /** 6 * Class Description: Generate 4-bit random verification code7 * @authorAuthor: Chenyanlong8 * @versionCreation Date: October 28, 20179 */Ten  Public classDemo2 { One  A      Public Static voidMain (string[] args) { -          -         Char[] arr={' Chen ', ' Yan ', ' Dragon ', ' a ', ' B ', ' C ', ' d '}; theRandom random=NewRandom (); -StringBuffer stb=NewStringBuffer (); -          -         //requires four random numbers to get the characters in the array by acquiring a random number of characters +          for(inti=0;i<4;i++){ -             intIndex=random.nextint (arr.length);//the resulting random number must be the index value range value of the array + stb.append (Arr[index]); A         } atSystem.out.println ("Generated random number:" +STB); -     } -}

Operating effect:

Java Foundation Basics Summary-----Random number (generates four random numbers)

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.