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)