create Lowercase Random String - Java java.lang

Java examples for java.lang:String Random

Description

create Lowercase Random String

Demo Code


//package com.java2s;

public class Main {
    public static final String ALL_LOWERCASE_VALUE = "abcdefghijklmnopqrstuvwxyz";

    public static String createLowercaseRandom(int length) {
        if (length < 1) {
            throw new IllegalArgumentException(
                    "length cannot be less than 1");
        }//ww  w .  ja va2s .c om
        int vLen = ALL_LOWERCASE_VALUE.length();
        String result = "";
        for (int i = 0; i < length; i++) {
            double dr = Math.random() * vLen;
            int ir = (int) Math.floor(dr);
            result += ALL_LOWERCASE_VALUE.charAt(ir);
        }
        return result;
    }
}

Related Tutorials