|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--sam.toolkit.Random
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 Long s randomly |
static java.lang.String |
drawString(java.lang.String[] strings)
Draws one of specified String s 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 |
public Random()
Method Detail |
public static boolean nextBoolean()
public static byte nextByte()
public static int nextInt()
public static long nextLong()
public static int nextInt(int limit)
0, limit - 1
.
limit
- the upper limit of the allowed range.
If limit
is less than 1
then 0
is returned.public static long nextLong(long limit)
0, limit - 1
.
limit
- the upper limit of the allowed range.
If limit
is less than 1
then 0
is returned.public static java.lang.String nextHex(int digits)
digits
- number of digits required, possibly arbitrarily large
digits
public static java.lang.String drawString(java.lang.String[] strings)
String
s randomly
strings
- the list of allowed strings
null
if strings
is null
or a randomly chosen long among strings
otherwisepublic static long drawLong(long[] longs)
Long
s randomly
longs
- the list of allowed longs
longs
is null
or a randomly chosen long among longs
otherwisepublic static void consume(int maximum)
public static void consume(int minimum, int maximum)
public static void consume(int minimum, int maximum, int stride)
Multi-threading is an excellent source of random-ness, since any process (even
non-Java
ones) of the system is involved.
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
.public static void main(java.lang.String[] args)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |