Name
Random
Synopsis
This class generates pseudo-random numbers based on an initial seed value.
The algorithm used is deterministic in that two instances of this class,
initialized with the same seed and subject to the same method calls in the
same order, will return identical sequences of numbers.
Subclasses can implement a different random number generation algorithm by
overriding the protected next()
method to return a
pseudo-random number with the specified number of bits.
The nextInt()
and nextLong()
methods
return the next pseudo-random integer and long values, respectively, from the
random number sequence of this generator. The default algorithm generates
numbers that are approximately evenly distributed over the total range of
values for the return type, which implies that there is an almost
equal chance that any given bit in the random value will be 0 or 1.
The setSeed()
can be used to set a new seed value from
which subsequent random numbers will be generated. The seed can also
be supplied when an instance of this class is created. A
Random
object constructed with its default constructor
is seeded with the current time, expressed as the number of milliseconds
since Jan 1st, 1970.
The CLDC implementation of this class does not include the J2SE methods for random floating point numbers (the CLDC VM does not support floating point values), nor does it offer the ability to obtain random boolean values and random-valued byte arrays.
public class Random { // Public Constructors ...
Get J2ME in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.