Java ThreadLocalRandom randomChar()

Here you can find the source of randomChar()

Description

Generates a pseudorandom char value, from 0 to 65535 inclusive.

License

Open Source License

Return

A random char .

Declaration

public static char randomChar() 

Method Source Code

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

import java.util.concurrent.ThreadLocalRandom;

public class Main {
    /**//w ww .  ja  v  a  2 s.  c o m
     * Generates a pseudorandom {@code char} value, from {@code 0} to 
     * {@code 65535} inclusive.
     * 
     * @return A random {@code char}.
     */
    public static char randomChar() {
        return randomChar(Character.MIN_VALUE, Character.MAX_VALUE);
    }

    /**
     * Generates a pseudorandom {@code char} value, from the given lower bound
     * to the given upper bound, inclusive.
     * 
     * @param lower Lower bound to generate character.
     * @param upper Upper bound to generate character.
     * @return A random {@code char}.
     */
    public static char randomChar(int lower, int upper) {
        return (char) ThreadLocalRandom.current().nextInt(lower, upper + 1);
    }
}

Related

  1. random(T[] array)
  2. randomAge()
  3. randomAlphabetic(int length)
  4. randomBoundedInclusiveInt(int start, int end)
  5. randomCase(String input)
  6. randomDelay()
  7. randomDouble(final double min, final double max)
  8. randomElement(Collection c, int n, boolean unique)
  9. randomEnum(Class clazz)