Here you can find the source of getRandomChar(boolean number, boolean lower, boolean upper, boolean other, String extra, Random _random)
Von http://www.jswelt.de/showsource.php?id=1123706440
Parameter | Description |
---|---|
number | a parameter |
lower | a parameter |
upper | a parameter |
other | a parameter |
extra | a parameter |
_random | a parameter |
public static char getRandomChar(boolean number, boolean lower, boolean upper, boolean other, String extra, Random _random)
//package com.java2s; //License from project: Open Source License import java.util.Random; public class Main { public final static String numberCharacters = "0123456789"; public final static String lowerCharacters = "abcdefghijklmnopqrstuvwxyz"; public final static String upperCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; public final static String otherCharacters = "%_!?"; /**// w w w . j av a 2 s .c o m * Von http://www.jswelt.de/showsource.php?id=1123706440 * * @param number * @param lower * @param upper * @param other * @param extra * @param _random * @return */ public static char getRandomChar(boolean number, boolean lower, boolean upper, boolean other, String extra, Random _random) { String charSet = extra; if (number == true) charSet += numberCharacters; if (lower == true) charSet += lowerCharacters; if (upper == true) charSet += upperCharacters; if (other == true) charSet += otherCharacters; return charSet.charAt(generateRandomInteger(0, (charSet.length() - 1), _random)); } /** * Erzeugt eine Zufallszahl * * @param aStart * @param aEnd * @param aRandom * @return */ public static int generateRandomInteger(int aStart, int aEnd, Random aRandom) { if (aStart > aEnd) { throw new IllegalArgumentException("Start cannot exceed End."); } // get the range, casting to long to avoid overflow problems long range = (long) aEnd - (long) aStart + 1; // compute a fraction of the range, 0 <= frac < range long fraction = (long) (range * aRandom.nextDouble()); int randomNumber = (int) (fraction + aStart); return randomNumber; } }