Random.Next(Int32) Method
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.
Generates the next pseudorandom number.
[Android.Runtime.Register("next", "(I)I", "GetNext_IHandler")]
protected virtual int Next (int bits);
[<Android.Runtime.Register("next", "(I)I", "GetNext_IHandler")>]
abstract member Next : int -> int
override this.Next : int -> int
Parameters
- bits
- Int32
random bits
Returns
the next pseudorandom value from this random number generator's sequence
- Attributes
Remarks
Generates the next pseudorandom number. Subclasses should override this, as this is used by all other methods.
The general contract of next
is that it returns an int
value and if the argument bits
is between 1
and 32
(inclusive), then that many low-order bits of the returned value will be (approximately) independently chosen bit values, each of which is (approximately) equally likely to be 0
or 1
. The method next
is implemented by class Random
by atomically updating the seed to
{@code (seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1)}
and returning
{@code (int)(seed >>> (48 - bits))}.
This is a linear congruential pseudorandom number generator, as defined by D. H. Lehmer and described by Donald E. Knuth in The Art of Computer Programming, Volume 2: Seminumerical Algorithms, section 3.2.1.
Added in 1.1.
Java documentation for java.util.Random.next(int)
.
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.