RandomGeneratorFactory Class

Definition

This is a factory class for generating multiple random number generators of a specific algorithm.

[Android.Runtime.Register("java/util/random/RandomGeneratorFactory", ApiSince=35, DoNotGenerateAcw=true)]
[Java.Interop.JavaTypeParameters(new System.String[] { "T extends java.util.random.RandomGenerator" })]
public sealed class RandomGeneratorFactory : Java.Lang.Object
[<Android.Runtime.Register("java/util/random/RandomGeneratorFactory", ApiSince=35, DoNotGenerateAcw=true)>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "T extends java.util.random.RandomGenerator" })>]
type RandomGeneratorFactory = class
    inherit Object
Inheritance
RandomGeneratorFactory
Attributes

Remarks

This is a factory class for generating multiple random number generators of a specific algorithm. RandomGeneratorFactory also provides methods for selecting random number generator algorithms.

A specific RandomGeneratorFactory can be located by using the RandomGeneratorFactory#of(String) method, where the argument string is the name of the algorithm required. The method RandomGeneratorFactory#all() produces a non-empty Stream of all available RandomGeneratorFactory RandomGeneratorFactorys that can be searched to locate a RandomGeneratorFactory suitable to the task.

There are three methods for constructing a RandomGenerator instance, depending on the type of initial seed required. RandomGeneratorFactory#create(long) is used for long seed construction, RandomGeneratorFactory#create(byte[]) is used for byte[] seed construction, and RandomGeneratorFactory#create() is used for random seed construction. Example;

{@code
               RandomGeneratorFactory<RandomGenerator> factory = RandomGeneratorFactory.of("Random");

                for (int i = 0; i < 10; i++) {
                    new Thread(() -> {
                        RandomGenerator random = factory.create(100L);
                        System.out.println(random.nextDouble());
                    }).start();
                }
            }

RandomGeneratorFactory also provides methods describing the attributes (or properties) of a generator and can be used to select random number generator algorithms. These methods are typically used in conjunction with RandomGeneratorFactory#all(). In this example, the code locates the RandomGeneratorFactory that produces RandomGenerator RandomGenerators with the highest number of state bits.

{@code
                RandomGeneratorFactory<RandomGenerator> best = RandomGeneratorFactory.all()
                    .sorted(Comparator.comparingInt(RandomGenerator::stateBits).reversed())
                    .findFirst()
                    .orElse(RandomGeneratorFactory.of("Random"));
                System.out.println(best.name() + " in " + best.group() + " was selected");

                RandomGenerator rng = best.create();
                System.out.println(rng.nextLong());
            }

Added in 17.

Java documentation for java.util.random.RandomGeneratorFactory.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Properties

Name Description
Class

Returns the runtime class of this Object.

(Inherited from Object)
Default

Returns a RandomGeneratorFactory meeting the minimal requirement of having an algorithm whose state bits are greater than or equal 64.

Handle

The handle to the underlying Android instance.

(Inherited from Object)
IsArbitrarilyJumpable

Return true if random generator can jump an arbitrarily specified distant point in the state cycle.

IsDeprecated

Return true if the implementation of RandomGenerator (algorithm) has been marked for deprecation.

IsHardware

Return true if random generator uses a hardware device (HRNG) to produce entropic input.

IsJumpable

Return true if random generator can jump a specified distant point in the state cycle.

IsLeapable

Return true if random generator is jumpable and can leap to a very distant point in the state cycle.

IsSplittable

Return true if random generator can be cloned into a separate object with the same properties but positioned further in the state cycle.

IsStatistical

Return true if random generator is computed using an arithmetic algorithm and is statistically deterministic.

IsStochastic

Return true if random generator is computed using external or entropic sources as inputs.

IsStreamable

Return true if random generator can be used to create java.util.stream.Stream Streams of random numbers.

JniIdentityHashCode

Gets the identity hash code assigned to this Java peer by the interop runtime.

(Inherited from Object)
JniPeerMembers
PeerReference

Gets the JNI object reference for this Java peer.

(Inherited from Object)
ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

(Inherited from Object)
ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

(Inherited from Object)

Methods

Name Description
Clone()

Creates and returns a copy of this object.

(Inherited from Object)
Create()

Create an instance of RandomGenerator based on algorithm chosen.

Create(Byte[])

Create an instance of RandomGenerator based on algorithm chosen providing a starting byte[] seed.

Create(Int64)

Create an instance of RandomGenerator based on algorithm chosen providing a starting long seed.

Dispose()

Releases the resources held by this Java peer.

(Inherited from Object)
Dispose(Boolean)

Releases the resources held by this Java peer.

(Inherited from Object)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
Equidistribution()

Returns the equidistribution of the algorithm.

GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
Group()

Return the group name of the algorithm used by the random number generator.

JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
Name()

Return the name of the algorithm used by the random number generator.

Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
Of(String)

Returns a RandomGeneratorFactory that can produce instances of RandomGenerator that utilize the namealgorithm.

Period()

Return the period of the algorithm used by the random number generator.

SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
StateBits()

Returns number of bits used by the algorithm to maintain state of seed.

ToArray<T>()

Creates a managed array from this Java array wrapper.

(Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime()

Unregisters this Java peer from the interop runtime.

(Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Explicit Interface Implementations

Name Description
IJavaPeerable.Disposed()

Notifies the interop runtime that this managed peer has been disposed.

(Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced()

Releases this Java peer unless it is retained by another managed reference.

(Inherited from Object)
IJavaPeerable.Finalized()

Notifies the interop runtime that this managed peer has been finalized.

(Inherited from Object)
IJavaPeerable.JniManagedPeerState

Gets the state that describes the relationship between this managed peer and its JNI reference.

(Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32)

Sets the interop identity hash code for this Java peer.

(Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates)

Sets the managed and JNI peer state for this Java peer.

(Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference)

Sets the JNI object reference used by this managed peer.

(Inherited from Object)

Extension Methods

Name Description
GetJniTypeName(IJavaPeerable)

Gets the JNI name of the type of the instance self.

JavaAs<TResult>(IJavaPeerable)

Try to coerce self to type TResult, checking that the coercion is valid on the Java side.

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
TryJavaCast<TResult>(IJavaPeerable, TResult)

Try to coerce self to type TResult, checking that the coercion is valid on the Java side.

Applies to