random Char - Java java.util

Java examples for java.util:Random

Description

random Char

Demo Code


//package com.java2s;

public class Main {
    private static char randomChar() {
        if (Math.random() > 0.5) {
            return (char) ((int) '0' + random(0, 9));
        } else {//from  w w  w . j  a  va  2  s  .  c  om
            return (char) ((int) 'A' + random(0, 25));
        }
    }

    public static int random(int min, int max) {
        assert (min <= max);
        return min + (int) Math.round(Math.random() * (double) (max - min));
    }

    public static Object random(Object values[]) {
        assert (values != null);
        return values[random(0, values.length - 1)];
    }
}

Related Tutorials