com.croftsoft.core.math
Class RandomLib

java.lang.Object
  extended by com.croftsoft.core.math.RandomLib

public class RandomLib
extends Object

Random number generation methods.

Since:
1999-01-31
Version:
2003-04-21
Author:
David Wallace Croft

Constructor Summary
RandomLib()
           
 
Method Summary
static void main(String[] args)
          Test method; prints roll(arg0, arg1, arg2).
static long nextLong(long n)
          Returns a long between 0 (inclusive) and n (exclusive).
static long roll(long multiplier, long base, long offset)
          Rolls an n-sided die a specified number of times and adds an offset.
static double uniform(double min, double max)
          Returns a double uniformly distributed between min (inclusive) and max (exclusive).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RandomLib

public RandomLib()
Method Detail

main

public static void main(String[] args)
Test method; prints roll(arg0, arg1, arg2).


nextLong

public static long nextLong(long n)
Returns a long between 0 (inclusive) and n (exclusive).

Throws:
IllegalArgumentException - If n is negative.

roll

public static long roll(long multiplier,
                        long base,
                        long offset)
Rolls an n-sided die a specified number of times and adds an offset. For example, to roll a 6-sided die 3 times and add 4 (3d6+4), the multiplier would be 3, the base 6, and the offset 4.

Parameters:
multiplier - The number of times to roll the die. Must be non-negative.
base - The number of sides on the die, e.g., six.
offset - A final adjustment to add to the sum after all rolls have been made.
Returns:
Returns the sum of the rolls plus the offset. The overflow condition is not handled.

uniform

public static double uniform(double min,
                             double max)
Returns a double uniformly distributed between min (inclusive) and max (exclusive).


CroftSoft Javadoc

CroftSoft Core Javadoc (2008-09-28 20:58:02)