Udostępnij za pośrednictwem


Random.NextBytes(Byte[]) Method

Definition

Generates random bytes and places them into a user-supplied byte array.

[Android.Runtime.Register("nextBytes", "([B)V", "GetNextBytes_arrayBHandler")]
public virtual void NextBytes (byte[]? bytes);
[<Android.Runtime.Register("nextBytes", "([B)V", "GetNextBytes_arrayBHandler")>]
abstract member NextBytes : byte[] -> unit
override this.NextBytes : byte[] -> unit

Parameters

bytes
Byte[]

the byte array to fill with random bytes

Attributes

Remarks

Generates random bytes and places them into a user-supplied byte array. The number of random bytes produced is equal to the length of the byte array.

The method nextBytes is implemented by class Random as if by:

{@code
            public void nextBytes(byte[] bytes) {
              for (int i = 0; i < bytes.length; )
                for (int rnd = nextInt(), n = Math.min(bytes.length - i, 4);
                     n-- > 0; rnd >>= 8)
                  bytes[i++] = (byte)rnd;
            }}

Added in 1.1.

Java documentation for java.util.Random.nextBytes(byte[]).

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.

Applies to