com.partnersoft.data
Class RandomLib

java.lang.Object
  extended by com.partnersoft.data.RandomLib
All Implemented Interfaces:
Lib

public class RandomLib
extends java.lang.Object
implements Lib

Various games of chance.

Uses a single Random for generation, except where noted.

Don't trust this for cryptographic purposes; if you need to be sure of the security your random numbers, generate your own. The underlying implementation of this class may change if performance or other considerations dictate.

Copyright 2005-2006 Partner Software, Inc.

Version:
$Id: RandomLib.java 1946 2009-06-29 13:17:15Z paul $
Author:
Paul Reavis

Method Summary
static boolean randomBoolean()
          Generates a random true/false result.
static byte[] randomBytes(int size)
          Generates a String of the given length consisting of random digits.
static int randomDigit()
          randoms a single digit 0-9 inclusive.
static java.lang.String randomGuid()
          Generates a random GUID.
static int randomInt(int limit)
          Generates a random integer between 0 <= result < limit
static int randomInt(int min, int max)
          Generates a random integer between the two bounds such that min <= result <= max.
static byte[] randomLengthBytes(int maxSize)
          Generates a random-length String consisting of random digits, up to the given length.
static java.lang.String randomLengthStringOfDigits(int maxSize)
          Generates a random-length String consisting of random digits, up to the given length.
static int randomNonZeroDigit()
          Generates a single random digit 1-9 inclusive.
static java.lang.String randomPhoneNumber()
          Generates a random phone number.
static java.lang.Object randomPick(java.util.Collection options)
          Picks a random item out of a Collection.
static java.lang.Object randomRemove(java.util.Collection options)
          Removes a random item from a Collection.
static java.lang.String randomStringOfDigits(int size)
          Generates a String of the given length consisting of random digits.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

randomInt

public static int randomInt(int limit)
Generates a random integer between 0 <= result < limit


randomInt

public static int randomInt(int min,
                            int max)
Generates a random integer between the two bounds such that min <= result <= max.


randomDigit

public static int randomDigit()
randoms a single digit 0-9 inclusive.


randomNonZeroDigit

public static int randomNonZeroDigit()
Generates a single random digit 1-9 inclusive.


randomPhoneNumber

public static java.lang.String randomPhoneNumber()
Generates a random phone number. Do not use for crank calls, please.


randomPick

public static java.lang.Object randomPick(java.util.Collection options)
Picks a random item out of a Collection. Does not modify the collection.


randomRemove

public static java.lang.Object randomRemove(java.util.Collection options)
Removes a random item from a Collection.


randomGuid

public static java.lang.String randomGuid()
Generates a random GUID. Uses UUID.randomUUID(); the only difference is that it surrounds the GUID string with curly braces ({ and }). This is for interoperability with PDA/Origin GIS GUIDs (which use a Microsoft standard, I believe).


randomLengthStringOfDigits

public static java.lang.String randomLengthStringOfDigits(int maxSize)
Generates a random-length String consisting of random digits, up to the given length.


randomStringOfDigits

public static java.lang.String randomStringOfDigits(int size)
Generates a String of the given length consisting of random digits.


randomLengthBytes

public static byte[] randomLengthBytes(int maxSize)
Generates a random-length String consisting of random digits, up to the given length.


randomBytes

public static byte[] randomBytes(int size)
Generates a String of the given length consisting of random digits.


randomBoolean

public static boolean randomBoolean()
Generates a random true/false result.

Returns: