Java Random generateRandom(int length, int type)

Here you can find the source of generateRandom(int length, int type)

Description

generate Random

License

Apache License

Declaration

public static String generateRandom(int length, int type) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {

    public static String generateRandom(int length, int type) {
        if (1 == type) {
            Random r = new Random();
            int randNum = 0;
            while (randNum < 100000) {
                randNum = (int) r.nextInt(999999);
            }//from   w  w w.j  a v  a  2  s.  c  o m
            return randNum + "";
        }
        String base = null;
        if (2 == type) {
            base = "abcdefghijklmnopqrstuvwxyz";
        } else {
            base = "abcdefghijklmnopqrstuvwxyz0123456789";
        }
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }
        return sb.toString();
    }
}

Related

  1. equalsRandomIterable(List a, List bl)
  2. extractRandomObject(Collection c)
  3. extractRandomVector(Collection c, int newSize)
  4. gaussianInt(Random random, int min, int max)
  5. generateRandom(byte[] byteArray)
  6. generateRandom(Integer bitNum)
  7. generateRandomIntegerId()
  8. generateRandomNo()
  9. GenerateRandomPin()