Java Random Char randomCharacter(boolean includeSymbols)

Here you can find the source of randomCharacter(boolean includeSymbols)

Description

random Character

License

Open Source License

Declaration

public static char randomCharacter(boolean includeSymbols) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    private static String CHARS = "123456789ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijklmnpqrstuvwxyz";
    private static String SYMBOLS_AND_CHARS = "{|}~!#$%&()*+,-.:;<=>?@[]^_" + CHARS;

    public static char randomCharacter(boolean includeSymbols) {
        if (includeSymbols) {
            int ival = (int) (Math.random() * SYMBOLS_AND_CHARS.length());
            return SYMBOLS_AND_CHARS.charAt(ival);
        } else {/*from  w  w  w  .  ja  v  a  2 s .  co m*/
            int ival = (int) (Math.random() * CHARS.length());
            return CHARS.charAt(ival);
        }
    }
}

Related

  1. randomChar()
  2. randomChar()
  3. randomChar()
  4. randomChar(char[] letters)
  5. randomChar(Random r)
  6. randomChars(char[] alphabet, int length)