Java Random Char getRandomChar(int size)

Here you can find the source of getRandomChar(int size)

Description

Description:

License

Open Source License

Parameter

Parameter Description
size <br>

Return


Declaration

public static String getRandomChar(int size) 

Method Source Code

//package com.java2s;

import java.util.Random;

public class Main {
    /**//from  w  w w  .  ja  v  a2 s  .c om
     * random
     */
    private static final Random RANDOM = new Random();

    /**
     * Description: <br>
     * 
     * @author yang.zhipeng <br>
     * @taskId <br>
     * @param size <br>
     * @return <br>
     */
    public static String getRandomChar(int size) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < size; i++) {
            switch (RANDOM.nextInt(10) % 3) {
            case 0:
                sb.append((char) ('0' + RANDOM.nextInt(10)));
                break;
            case 1:
                sb.append((char) ('a' + RANDOM.nextInt(26)));
                break;
            case 2:
                sb.append((char) ('A' + RANDOM.nextInt(26)));
                break;
            default:
                ;
            }
        }
        return sb.toString();
    }
}

Related

  1. createRandomChar()
  2. getRandomChar()
  3. getRandomChar()
  4. getRandomChar()
  5. getRandomChar(boolean number, boolean lower, boolean upper, boolean other, String extra, Random _random)
  6. getRandomChar(int x)
  7. getRandomChar(int[][] ranges, char differentThen, boolean caseSensitive, Random random)
  8. getRandomChar(Random random, boolean upper)
  9. getRandomChar(Random random, int type)