generate random String from current time - Java java.lang

Java examples for java.lang:String Random

Description

generate random String from current time

Demo Code


//package com.java2s;
import java.util.Random;

public class Main {
    public static void main(String[] argv) {
        System.out.println(randomString());
    }/*  www  . j  a v  a2s  .co m*/

    public static String randomString() {
        return randomString(8);
    }

    public static String randomString(int count) {
        Random rnd = new Random(System.currentTimeMillis());
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < count; i++) {
            sb.append((char) (rnd.nextInt(25) + 97));
        }
        return sb.toString();
    }
}

Related Tutorials