CryptGenRandom (advapi32)
Last changed: havramm-212.62.55.22

.
Summary
The CryptGenRandom function fills a buffer with cryptographically random bytes.

C# Signature:

[DllImport("advapi32.dll", SetLastError=true)]
static extern bool CryptGenRandom(IntPtr hProv, uint dwLen, byte[] pbBuffer);

VB Signature:

Declare Function CryptGenRandom Lib "advapi32.dll" (ByVal hProv As IntPtr, ByVal dwLen As Integer, ByVal pbBuffer As Byte()) As Boolean

User-Defined Types:

None.

Alternative Managed API:

The RNGCryptoServiceProvider class

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

byte[] newRandom = new byte[10];

if (!CryptGenRandom(hProv, (uint)(newRandom.Length), newRandom))

{

    throw new Win32Exception(Marshal.GetLastWin32Error());

}

Documentation