Java Random String generateRandomCode()

Here you can find the source of generateRandomCode()

Description

generate Random Code

License

Open Source License

Declaration

public static String generateRandomCode() 

Method Source Code

//package com.java2s;
/*//from  w  w  w. jav  a 2 s. co  m
 * [y] hybris Platform
 * 
 * Copyright (c) 2000-2015 hybris AG
 * All rights reserved.
 * 
 * This software is the confidential and proprietary information of hybris
 * ("Confidential Information"). You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the
 * license agreement you entered into with hybris.
 */

public class Main {
    public static String generateRandomCode() {
        final StringBuffer randomString = new StringBuffer();

        for (int i = 0; i < 5; i++) {
            char c = 'A';
            c = (char) (c + (int) (Math.random() * 26));
            randomString.append(c);
        }
        return randomString.toString();
    }
}

Related

  1. createRandomWord(boolean startWithCapital)
  2. generateRandom(int num)
  3. generateRandom(Integer digits)
  4. generateRandomChain(int length)
  5. generateRandomCharacters(int N)
  6. generateRandomSentence()
  7. generateRandomStr(final int length)
  8. generateRandomStr(int length)
  9. generateRandomString()