sam.toolkit
Class Random

java.lang.Object
  |
  +--sam.toolkit.Random

public class Random
extends java.lang.Object

Random numbers generator. This is basically an enhanced version of the Random generator. It ties to be even more unpredictable by spawning arbitrarily scheduled consumer threads.

Instances of this class are fully immutable.


Nested Class Summary
static class Random.IntegerSetRandomizer
          Class for randomizing over fixed integer sets.
 
Constructor Summary
Random()
           
 
Method Summary
static void consume(int maximum)
          Spawns a new thread which at random times consums the random generator
static void consume(int minimum, int maximum)
          Spawns a new thread which at random times consums the random generator
static void consume(int minimum, int maximum, int stride)
          Spawns a new thread which at random times consums the random generator
static long drawLong(long[] longs)
          Draws one of specified Longs randomly
static java.lang.String drawString(java.lang.String[] strings)
          Draws one of specified Strings randomly
static void main(java.lang.String[] args)
           
static boolean nextBoolean()
          Draws a boolean randomly.
static byte nextByte()
          Draws a byte randomly.
static java.lang.String nextHex(int digits)
          Draws an hexadecimal sequence of specified length.
static int nextInt()
          Draws an integer randomly.
static int nextInt(int limit)
          Draws an integer randomly in the range 0, limit - 1.
static long nextLong()
          Draws a long integer randomly.
static long nextLong(long limit)
          Draws a long integer randomly in the range 0, limit - 1.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Random

public Random()
Method Detail

nextBoolean

public static boolean nextBoolean()
Draws a boolean randomly.


nextByte

public static byte nextByte()
Draws a byte randomly.


nextInt

public static int nextInt()
Draws an integer randomly.


nextLong

public static long nextLong()
Draws a long integer randomly.


nextInt

public static int nextInt(int limit)
Draws an integer randomly in the range 0, limit - 1.

Parameters:
limit - the upper limit of the allowed range. If limit is less than 1 then 0 is returned.

nextLong

public static long nextLong(long limit)
Draws a long integer randomly in the range 0, limit - 1.

Parameters:
limit - the upper limit of the allowed range. If limit is less than 1 then 0 is returned.

nextHex

public static java.lang.String nextHex(int digits)
Draws an hexadecimal sequence of specified length.

Parameters:
digits - number of digits required, possibly arbitrarily large
Returns:
an hexadecimal string of length digits

drawString

public static java.lang.String drawString(java.lang.String[] strings)
Draws one of specified Strings randomly

Parameters:
strings - the list of allowed strings
Returns:
null if strings is null or a randomly chosen long among strings otherwise

drawLong

public static long drawLong(long[] longs)
Draws one of specified Longs randomly

Parameters:
longs - the list of allowed longs
Returns:
0 if longs is null or a randomly chosen long among longs otherwise

consume

public static void consume(int maximum)
Spawns a new thread which at random times consums the random generator


consume

public static void consume(int minimum,
                           int maximum)
Spawns a new thread which at random times consums the random generator


consume

public static void consume(int minimum,
                           int maximum,
                           int stride)
Spawns a new thread which at random times consums the random generator

Multi-threading is an excellent source of random-ness, since any process (even non-Java ones) of the system is involved.

Parameters:
minimum - minimum duration (in milliseconds) between two consumptions. Default is maximum / 10
maximum - maximum duration (in milliseconds) between two consumptions.
stride - stride (in milliseconds) of randomly-choosen sleep times . Default is equal minimum.

main

public static void main(java.lang.String[] args)