RandomGeneratorFactory Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
- 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
Class |
Returns the runtime class of this |
Default |
Returns a |
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
|
JniIdentityHashCode | (Inherited from Object) |
JniPeerMembers | |
PeerReference | (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
Clone() |
Creates and returns a copy of this object. (Inherited from Object) |
Create() |
Create an instance of |
Create(Byte[]) |
Create an instance of |
Create(Int64) |
Create an instance of |
Dispose() | (Inherited from Object) |
Dispose(Boolean) | (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 |
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>() | (Inherited from Object) |
ToString() |
Returns a string representation of the object. (Inherited from Object) |
UnregisterFromRuntime() | (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
IJavaPeerable.Disposed() | (Inherited from Object) |
IJavaPeerable.DisposeUnlessReferenced() | (Inherited from Object) |
IJavaPeerable.Finalized() | (Inherited from Object) |
IJavaPeerable.JniManagedPeerState | (Inherited from Object) |
IJavaPeerable.SetJniIdentityHashCode(Int32) | (Inherited from Object) |
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) | (Inherited from Object) |
IJavaPeerable.SetPeerReference(JniObjectReference) | (Inherited from Object) |
Extension Methods
JavaCast<TResult>(IJavaObject) |
Performs an Android runtime-checked type conversion. |
JavaCast<TResult>(IJavaObject) | |
GetJniTypeName(IJavaPeerable) |
Gets the JNI name of the type of the instance |
JavaAs<TResult>(IJavaPeerable) |
Try to coerce |
TryJavaCast<TResult>(IJavaPeerable, TResult) |
Try to coerce |