get Random Name - Java java.util

Java examples for java.util:Random

Description

get Random Name

Demo Code


//package com.java2s;

import java.text.SimpleDateFormat;
import java.util.Date;

import java.util.Random;

public class Main {
    public static void main(String[] argv) throws Exception {
        System.out.println(getRandomName());
    }//  w w w  . ja va 2s.  c  o m

    public static String getRandomName() {
        Random r = new Random();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmssSSS");
        StringBuffer sb = new StringBuffer();
        sb.append(r.nextInt(100));
        sb.append(r.nextInt(100));
        sb.append("_");
        sb.append(sdf.format(new Date()));
        sb.append("_");
        sb.append(r.nextInt(100));
        sb.append(r.nextInt(100));
        return sb.toString();
    }
}

Related Tutorials