/*** Algorithmutil.java * com.tfedu.yuwen.util * Copyright (c) 2017, Beijing Poly-Wisdom Future Technology Co., Ltd. All rights reserved.*/ PackageCom.tfedu.yuwen.util;ImportJava.util.Random;/*** Algorithm Tool class * <p> * language really good in various algorithms *@authorKuangxiang ([email protected]) * @Date September 18, 2017*/ Public classAlgorithmutil {/*** Number of digits * <P> * Set the number of bits to generate the string*/ Private Static Final intDIGIT = 8; /*** Verify number of code digits*/ Private Static Final intVerifycodedigit = 6; /*** * Generate ring ID * <P> * 8-digit combination of uppercase letters and numbers, which do not have to appear at the same time, but the characters can recur, but must be unique * *@returnstring*/ Public StaticString generatesign () {inti; intCount = 0; Char[] str = {' A ', ' B ', ' C ', ' D ', ' E ', ' F ', ' G ', ' H ', ' I ', ' J ', ' K ', ' L ', ' M ', ' N ', ' O ', ' P ', ' Q ', ' R ', ' S ', ' T ', ' U ', ' V ', ' W ', ' X ', ' Y ', ' Z ', ' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 ' }; StringBuffer pwd=NewStringBuffer (""); Random R=NewRandom (); while(Count <DIGIT) {i=Math.Abs (R.nextint (str.length)); if(I >= 0 && i <str.length) {pwd.append (str[i]); Count++; } } returnpwd.tostring (); } /*** Generate Verification code * *@returnVerification Code character channeling*/ Public StaticString Generateverifycode () {inti; intCount = 0; Char[] str = {' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 ' }; StringBuffer pwd=NewStringBuffer (""); Random R=NewRandom (); while(Count <verifycodedigit) {i=Math.Abs (R.nextint (str.length)); if(I >= 0 && i <str.length) {pwd.append (str[i]); Count++; } } returnpwd.tostring (); }}
Get a combination of letters and numbers in Java