Home  |  Delphi .net Home  |  System.Random  |  NextBytes Method
  
NextBytes  
Method  
Stores a sequence of random numbers in a Byte array
Random Class
System NameSpace
CF1.  Procedure NextBytes ( ByteArray : Array of Byte ) ;
CF : Methods with this mark are Compact Framework Compatible
Description
Stores a sequence of random byte values (in the range 0 to 255) into the supplied ByteArray.
Notes
The array is a primitive array, not to be confused with System.Array
References
Array
Microsoft MSDN Links
System
System.Random
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

var
  rand    : System.Random;
  myArray : Array[0..4] of Byte;
  value   : Byte;
  i       : Integer;

begin
  rand    := System.Random.Create;

  Console.WriteLine('Array at the start :');

  for i := 0 to Length(myArray)-1 do
    Console.WriteLine('myArray[{0}] = {1}',
                      i.ToString,
                      myArray[i].ToString);

  rand.NextBytes(myArray);

  Console.WriteLine('After storing random numbers in the array :');

  for i := 0 to Length(myArray)-1 do
    Console.WriteLine('myArray[{0}] = {1}',
                      i.ToString,
                      myArray[i].ToString);

  Console.ReadLine;
end.
   Array at the start :
   myArray[0] = 0
   myArray[1] = 0
   myArray[2] = 0
   myArray[3] = 0
   myArray[4] = 0
   After storing random numbers in the array :
   myArray[0] = 175
   myArray[1] = 44
   myArray[2] = 234
   myArray[3] = 37
   myArray[4] = 122
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author