random String - Android java.util

Android examples for java.util:Random String

Description

random String

Demo Code


//package com.java2s;

import java.util.Random;

public class Main {
    private static final String CHAR_ARRAY = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    private static final Random RANDOM = new Random();

    public static final String randomString(int len) {
        StringBuffer sBuffer = new StringBuffer();
        int rang = CHAR_ARRAY.length();
        for (int index = 0; index < len; index++) {
            sBuffer.append(CHAR_ARRAY.charAt(RANDOM.nextInt(rang)));
        }/*w w  w. j a v a2 s.  c o  m*/
        return sBuffer.toString();
    }
}

Related Tutorials