RtlGenRandom function
[The RtlGenRandom function is available for use in the operating systems specified in the Requirements section. It may be altered or unavailable in subsequent versions. Instead, use the CryptGenRandom function.]
Applies to: desktop apps only
The RtlGenRandom function generates a pseudo-random number.
Note This function has no associated import library. This function is available as a resource named SystemFunction036 in Advapi32.dll. You must use the LoadLibrary and GetProcAddress functions to dynamically link to Advapi32.dll.
Syntax
BOOLEAN RtlGenRandom( __out PVOID RandomBuffer, __in ULONG RandomBufferLength );
Parameters
- RandomBuffer [out]
-
A pointer to a buffer that receives the random number as binary data. The size of this buffer is specified by the RandomBufferLength parameter.
- RandomBufferLength [in]
-
The length, in bytes, of the RandomBuffer buffer.
Return value
If the function succeeds, the function returns TRUE.
If the function fails, it returns FALSE.
Remarks
When you have finished using the random number, free the RandomBuffer buffer by calling the SecureZeroMemory function.
Requirements
|
Minimum supported client | Windows XP |
|---|---|
|
Minimum supported server | Windows Server 2003 |
|
Header |
|
|
DLL |
|
Send comments about this topic to Microsoft
Build date: 3/6/2012
The statement about there not being an import library is incorrect. It is AdvAPI32.lib, and is declared in NTSecAPI.h. If you use GetProcAddress to find this function, it is named SystemFunction036. If you use NTSecAPI.h, you can call it directly as either SystemFunction036 or RtlGenRandom.
There is an error in some versions of the Platform SDK headers where the prototype for RtlGenRandom is missing a calling convention specifier. If you are building for 32-bit x86, and your compiler's default calling convention is not set to __stdcall, your application will fail to link due to mismatched conventions. A example workaround is the following:
#define SystemFunction036 NTAPI SystemFunction036
#include <NTSecAPI.h>
#undef SystemFunction036
Finally, the statement that it may disappear in future versions is rather unlikely: the Microsoft C Runtime Library makes use of this function in its implementation of "rand_s".
- 6/16/2010
- Myria