Get a combination of letters and numbers in Java

Source: Internet
Author: User
Tags abs stringbuffer

  

/*** 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

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.