Oracle Fusion Middleware C++ API Reference for Oracle Coherence
12c (12.1.2)

E26041-01

Random Class Reference

#include <coherence/util/Random.hpp>

Inherits Object.

List of all members.


Detailed Description

An instance of this class is used to generate a stream of pseudorandom numbers.

This class is an implementation of D. H. Lehmer's linear congruential formula as described by Donald E. Knuth in: The Art of Computer Programming, Volume 2, Section 3.2.1.

Author:
js 2008.03.27

Public Types

typedef spec::Handle Handle
 Random Handle definition.
typedef spec::View View
 Random View definition.
typedef spec::Holder Holder
 Random Holder definition.

Public Member Functions

virtual int32_t nextInt32 (int32_t n)
 Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.
virtual bool nextBoolean ()
 Returns the next pseudorandom, uniformly distributed boolean value from this random number generator's sequence.
virtual int32_t nextInt32 ()
 Returns the next pseudorandom, uniformly distributed int32_t value from this random number generator's sequence.
virtual int64_t nextInt64 ()
 Returns the next pseudorandom, uniformly distributed int64_t value from this random number generator's sequence.
virtual float32_t nextFloat32 ()
 Returns the next pseudorandom, uniformly distributed float32_t value from this random number generator's sequence.
virtual float64_t nextFloat64 ()
 Returns the next pseudorandom, uniformly distributed float64_t value from this random number generator's sequence.
virtual void seed ()
 Provides a default seeding algorithm that is used to seed this random number if no seed is provided.
virtual void setSeed (int64_t lSeed)
 Sets the seed of this random number generator using a single long seed.

Static Public Member Functions

static
ObjectArray::Handle 
randomize (ObjectArray::Handle ha)
 Randomize the order of the elements within the passed array.
static List::Handle randomize (List::Handle hl)
 Randomize the order of the elements within the passed list.
static Handle getInstance ()
 Return the static Random instance.

Protected Member Functions

 Random ()
 Create a new Random instance without supplying a seed.
 Random (int64_t lSeed)
 Create a new Random instance, specifying a seed to use.
virtual int32_t next (int32_t nBits)
 Implementation of the random number algorithm which generates the next pseudorandom number.

Protected Attributes

NativeAtomic64 m_atomicSeed
 The internal state associated with this pseudorandom number generator.

Constructor & Destructor Documentation

Random (  )  [protected]

Create a new Random instance without supplying a seed.

The seed will be initialized by the default algorithm provided in seed().


Member Function Documentation

virtual int32_t nextInt32 ( int32_t  n  )  [virtual]

Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.

n the upper bound (exclusive) for the returned value

Returns:
an int32_t value in the range [0, n)
Exceptions:
IllegalArgumentException if n is <= 0

virtual bool nextBoolean (  )  [virtual]

Returns the next pseudorandom, uniformly distributed boolean value from this random number generator's sequence.

Returns:
the next bool value

virtual int32_t nextInt32 (  )  [virtual]

Returns the next pseudorandom, uniformly distributed int32_t value from this random number generator's sequence.

Returns:
the next int32_t value in the range [Integer32::min_value, Integer32::max_value]

virtual int64_t nextInt64 (  )  [virtual]

Returns the next pseudorandom, uniformly distributed int64_t value from this random number generator's sequence.

Returns:
the next int64_t value in the range [Integer64::min_value, Integer64::max_value]

virtual float32_t nextFloat32 (  )  [virtual]

Returns the next pseudorandom, uniformly distributed float32_t value from this random number generator's sequence.

Returns:
the next float32_t value in the range [0.0, 1.0]

virtual float64_t nextFloat64 (  )  [virtual]

Returns the next pseudorandom, uniformly distributed float64_t value from this random number generator's sequence.

Returns:
the next float64_t value in the range [0.0, 1.0]

static ObjectArray::Handle randomize ( ObjectArray::Handle  ha  )  [static]

Randomize the order of the elements within the passed array.

Parameters:
ha an array of objects to randomize
Returns:
the array that was passed in, with its contents unchanged except for the order in which they appear
Since:
Coherence 3.2

static List::Handle randomize ( List::Handle  hl  )  [static]

Randomize the order of the elements within the passed list.

Parameters:
ha a list of objects to randomize
Returns:
the list that was passed in, with its contents unchanged except for the order in which they appear
Since:
Coherence 3.4

virtual int32_t next ( int32_t  nBits  )  [protected, virtual]

Implementation of the random number algorithm which generates the next pseudorandom number.

Generates a 32 bit int value with it's corresponding bits being individually generated pseudorandom 1's and 0's. This method should be overridden to provide a new random number algorithm.

Parameters:
nBits number of random bits to generate
Returns:
the next pseudorandom number with the specified number of randomly generated bits

static Handle getInstance (  )  [static]

Return the static Random instance.

Returns:
the static Random instance


The documentation for this class was generated from the following file:
Copyright © 2000, 2013, Oracle and/or its affiliates. All rights reserved.