get Random Alpha String - Java java.util

Java examples for java.util:Random

Description

get Random Alpha String

Demo Code


//package com.java2s;

public class Main {
    public static String getRandomAlphaString(int length) {
        StringBuilder b = new StringBuilder();
        for (int i = 0; i < length; i++) {
            //   ascii 60 to 90
            char str = (char) (65 + (int) (Math.random() * (90 - 65)));
            b.append(str);//from   ww w. ja  v  a 2s  . co  m
        }

        return b.toString();
    }
}

Related Tutorials