IRandomGenerator Interface
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.
The RandomGenerator
interface is designed to provide a common
protocol for objects that generate random or (more typically) pseudorandom
sequences of numbers (or Boolean values).
[Android.Runtime.Register("java/util/random/RandomGenerator", "", "Java.Util.RandomGenerators.IRandomGeneratorInvoker", ApiSince=35)]
public interface IRandomGenerator : Android.Runtime.IJavaObject, IDisposable, Java.Interop.IJavaPeerable
[<Android.Runtime.Register("java/util/random/RandomGenerator", "", "Java.Util.RandomGenerators.IRandomGeneratorInvoker", ApiSince=35)>]
type IRandomGenerator = interface
interface IJavaObject
interface IDisposable
interface IJavaPeerable
- Derived
- Attributes
- Implements
Remarks
The RandomGenerator
interface is designed to provide a common protocol for objects that generate random or (more typically) pseudorandom sequences of numbers (or Boolean values). Such a sequence may be obtained by either repeatedly invoking a method that returns a single pseudorandomly chosen value, or by invoking a method that returns a stream of pseudorandomly chosen values.
Ideally, given an implicitly or explicitly specified range of values, each value would be chosen independently and uniformly from that range. In practice, one may have to settle for some approximation to independence and uniformity.
In the case of int
, long
, and boolean
values, if there is no explicit specification of range, then the range includes all possible values of the type. In the case of float
and double
values, first a value is always chosen uniformly from the set of 2<sup>w</sup> values between 0.0 (inclusive) and 1.0 (exclusive), where w is 23 for float
values and 52 for double
values, such that adjacent values differ by 2<sup>−w</sup> (notice that this set is a subset of the set of all representable floating-point values between 0.0 (inclusive) and 1.0 (exclusive)); then if an explicit range was specified, then the chosen number is computationally scaled and translated so as to appear to have been chosen approximately uniformly from that explicit range.
Each method that returns a stream produces a stream of values each of which is chosen in the same manner as for a method that returns a single pseudorandomly chosen value. For example, if r
implements RandomGenerator
, then the method call r.ints(100)
returns a stream of 100 int
values. These are not necessarily the exact same values that would have been returned if instead r.nextInt()
had been called 100 times; all that is guaranteed is that each value in the stream is chosen in a similar pseudorandom manner from the same range.
Every object that implements the RandomGenerator
interface by using a pseudorandom algorithm is assumed to contain a finite amount of state. Using such an object to generate a pseudorandomly chosen value alters its state by computing a new state as a function of the current state, without reference to any information other than the current state. The number of distinct possible states of such an object is called its period. (Some implementations of the RandomGenerator
interface may be truly random rather than pseudorandom, for example relying on the statistical behavior of a physical object to derive chosen values. Such implementations do not have a fixed period.)
As a rule, objects that implement the RandomGenerator
interface need not be thread-safe. It is recommended that multithreaded applications use either ThreadLocalRandom
or (preferably) pseudorandom number generators that implement the SplittableGenerator
or JumpableGenerator
interface.
Objects that implement RandomGenerator
are typically not cryptographically secure. Consider instead using SecureRandom
to get a cryptographically secure pseudorandom number generator for use by security-sensitive applications. Note, however, that SecureRandom
does implement the RandomGenerator
interface, so that instances of SecureRandom
may be used interchangeably with other types of pseudorandom generators in applications that do not require a secure generator.
Unless explicit stated otherwise, the use of null for any method argument will cause a NullPointerException.
Added in 17.
Java documentation for java.util.random.RandomGenerator
.
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
Default |
Returns a |
Handle |
Gets the JNI value of the underlying Android object. (Inherited from IJavaObject) |
IsDeprecated |
Return true if the implementation of RandomGenerator (algorithm) has been marked for deprecation. |
JniIdentityHashCode |
Returns the value of |
JniManagedPeerState |
State of the managed peer. (Inherited from IJavaPeerable) |
JniPeerMembers |
Member access and invocation support. (Inherited from IJavaPeerable) |
PeerReference |
Returns a JniObjectReference of the wrapped Java object instance. (Inherited from IJavaPeerable) |
Methods
Disposed() |
Called when the instance has been disposed. (Inherited from IJavaPeerable) |
DisposeUnlessReferenced() |
If there are no outstanding references to this instance, then
calls |
Finalized() |
Called when the instance has been finalized. (Inherited from IJavaPeerable) |
NextBoolean() |
Returns a pseudorandomly chosen |
NextBytes(Byte[]) |
Fills a user-supplied byte array with generated byte values pseudorandomly chosen uniformly from the range of values between -128 (inclusive) and 127 (inclusive). |
NextDouble() |
Returns a pseudorandom |
NextDouble(Double, Double) |
Returns a pseudorandomly chosen |
NextDouble(Double) |
Returns a pseudorandomly chosen |
NextExponential() |
Returns a nonnegative |
NextFloat() |
Returns a pseudorandom |
NextFloat(Single, Single) |
Returns a pseudorandomly chosen |
NextFloat(Single) |
Returns a pseudorandomly chosen |
NextGaussian() |
Returns a |
NextGaussian(Double, Double) |
Returns a |
NextInt() |
Returns a pseudorandomly chosen |
NextInt(Int32, Int32) |
Returns a pseudorandomly chosen |
NextInt(Int32) |
Returns a pseudorandomly chosen |
NextLong() |
Returns a pseudorandomly chosen |
NextLong(Int64, Int64) |
Returns a pseudorandomly chosen |
NextLong(Int64) |
Returns a pseudorandomly chosen |
Of(String) |
Returns an instance of |
SetJniIdentityHashCode(Int32) |
Set the value returned by |
SetJniManagedPeerState(JniManagedPeerStates) | (Inherited from IJavaPeerable) |
SetPeerReference(JniObjectReference) |
Set the value returned by |
UnregisterFromRuntime() |
Unregister this instance so that the runtime will not return it from future Java.Interop.JniRuntime+JniValueManager.PeekValue invocations. (Inherited from IJavaPeerable) |
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 |