Here you can find the source of getRandomChar(int size)
Parameter | Description |
---|---|
size | <br> |
public static String getRandomChar(int size)
//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(); } }