DthingApi
Public Member Functions | Protected Member Functions | List of all members
java.util.Random Class Reference

Public Member Functions

 Random ()
 
 Random (long seed)
 
boolean nextBoolean ()
 
void nextBytes (byte[] buf)
 
double nextDouble ()
 
float nextFloat ()
 
int nextInt ()
 
int nextInt (int n)
 
long nextLong ()
 
synchronized void setSeed (long seed)
 

Protected Member Functions

synchronized int next (int bits)
 

Detailed Description

This class provides methods that return pseudo-random values.

It is dangerous to seed

with the current time because that value is more predictable to an attacker than the default seed.

This class is thread-safe.

See also
java.security.SecureRandom

Constructor & Destructor Documentation

◆ Random() [1/2]

java.util.Random.Random ( )
inline

Constructs a random generator with an initial state that is unlikely to be duplicated by a subsequent instantiation.

The initial state (that is, the seed) is partially based on the current time of day in milliseconds.

◆ Random() [2/2]

java.util.Random.Random ( long  seed)
inline

Construct a random generator with the given

seed

as the initial state. Equivalent to

Random r = new Random(); r.setSeed(seed);

.

This constructor is mainly useful for predictability in tests. The default constructor is likely to provide better randomness.

Member Function Documentation

◆ next()

synchronized int java.util.Random.next ( int  bits)
inlineprotected

Returns a pseudo-random uniformly distributed

int

value of the number of bits specified by the argument

bits

as described by Donald E. Knuth in The Art of Computer Programming, Volume 2: Seminumerical Algorithms, section 3.2.1.

Most applications will want to use one of this class' convenience methods instead.

◆ nextBoolean()

boolean java.util.Random.nextBoolean ( )
inline

Returns a pseudo-random uniformly distributed

boolean

.

◆ nextBytes()

void java.util.Random.nextBytes ( byte []  buf)
inline

Fills

buf

with random bytes.

◆ nextDouble()

double java.util.Random.nextDouble ( )
inline

Returns a pseudo-random uniformly distributed

double

in the half-open range [0.0, 1.0).

◆ nextFloat()

float java.util.Random.nextFloat ( )
inline

Returns a pseudo-random uniformly distributed

float

in the half-open range [0.0, 1.0).

◆ nextInt() [1/2]

int java.util.Random.nextInt ( )
inline

Returns a pseudo-random uniformly distributed

int

.

◆ nextInt() [2/2]

int java.util.Random.nextInt ( int  n)
inline

Returns a pseudo-random uniformly distributed

int

in the half-open range [0, n).

◆ nextLong()

long java.util.Random.nextLong ( )
inline

Returns a pseudo-random uniformly distributed

long

.

◆ setSeed()

synchronized void java.util.Random.setSeed ( long  seed)
inline

Modifies the seed using a linear congruential formula presented in The Art of Computer Programming, Volume 2, Section 3.2.1.


The documentation for this class was generated from the following file: