tips.random
Class RandomValues

java.lang.Object
  extended bytips.random.RandomValues

public class RandomValues
extends java.lang.Object

RandomValues Sample class that demonstrates how to generate a random number between two values.

Since:
J2SE 1.4.2 Date 27/3/2004

Field Summary
private  java.util.Random m_Random
           
 
Constructor Summary
(package private) RandomValues()
          Create the object - and create the random number generator java.util.Random
 
Method Summary
static void main(java.lang.String[] args)
          Run this to demonstrate the algorithm is working...
 int next(int nLower, int nUpper)
          Get hold of a random number between the values of nLower and nUpper.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_Random

private java.util.Random m_Random
Constructor Detail

RandomValues

RandomValues()
Create the object - and create the random number generator java.util.Random

Method Detail

main

public static void main(java.lang.String[] args)
Run this to demonstrate the algorithm is working...

First create an object and then loop 1000 times returning a random number between 2 values. If that number is outside the range then report the error

Parameters:
args - There are no input arguments

next

public int next(int nLower,
                int nUpper)
         throws java.lang.Exception
Get hold of a random number between the values of nLower and nUpper.

Parameters:
nUpper - The upper of limit
nLower - The lower limit
Returns:
int - the new value.
Throws:
java.lang.Exception - when the input params are incorrect or the random number generator fails.