ReactOS  0.4.15-dev-489-g75a0787
random.c File Reference
#include <rtl.h>
#include <debug.h>
Include dependency graph for random.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define LCG_A   0x7fffffed
 
#define LCG_C   0x7fffffc3
 
#define LCG_M   MAXLONG
 

Functions

ULONG NTAPI RtlRandom (IN OUT PULONG Seed)
 
ULONG NTAPI RtlRandomEx (IN OUT PULONG Seed)
 
ULONG NTAPI RtlUniform (IN PULONG Seed)
 

Variables

static ULONG RtlpRandomConstantVector [128]
 
static ULONG RtlpRandomExConstantVector [128]
 
static ULONG RtlpRandomExAuxVarY = 0x7775fb16
 

Macro Definition Documentation

◆ LCG_A

#define LCG_A   0x7fffffed

Definition at line 91 of file random.c.

◆ LCG_C

#define LCG_C   0x7fffffc3

Definition at line 92 of file random.c.

◆ LCG_M

#define LCG_M   MAXLONG

Definition at line 93 of file random.c.

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file random.c.

Function Documentation

◆ RtlRandom()

ULONG NTAPI RtlRandom ( IN OUT PULONG  Seed)

Definition at line 113 of file random.c.

114 {
115  ULONG Rand;
116  int Pos;
117  ULONG Result;
118 
119  PAGED_CODE_RTL();
120 
121  Rand = (*Seed * LCG_A + LCG_C) % LCG_M;
122  *Seed = (Rand * LCG_A + LCG_C) % LCG_M;
123  Pos = *Seed & (sizeof(RtlpRandomConstantVector) / sizeof(RtlpRandomConstantVector[0]) - 1);
126 
127  return Result;
128 }
#define LCG_M
Definition: random.c:93
ush Pos
Definition: deflate.h:92
#define PAGED_CODE_RTL()
Definition: rtlp.h:16
#define LCG_A
Definition: random.c:91
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
static ULONG RtlpRandomConstantVector[128]
Definition: random.c:17
unsigned int ULONG
Definition: retypes.h:1
#define LCG_C
Definition: random.c:92

◆ RtlRandomEx()

ULONG NTAPI RtlRandomEx ( IN OUT PULONG  Seed)

Definition at line 150 of file random.c.

152 {
153  ULONG Rand;
154  int Pos;
155 
156  PAGED_CODE_RTL();
157 
160  Rand = (*Seed * LCG_A + LCG_C) % LCG_M;
162  *Seed = Rand;
163 
164  return Rand;
165 }
#define LCG_M
Definition: random.c:93
static ULONG RtlpRandomExAuxVarY
Definition: random.c:89
ush Pos
Definition: deflate.h:92
#define PAGED_CODE_RTL()
Definition: rtlp.h:16
#define LCG_A
Definition: random.c:91
static ULONG RtlpRandomExConstantVector[128]
Definition: random.c:53
unsigned int ULONG
Definition: retypes.h:1
#define LCG_C
Definition: random.c:92

Referenced by KsecGenRandom().

◆ RtlUniform()

ULONG NTAPI RtlUniform ( IN PULONG  Seed)

Definition at line 195 of file random.c.

196 {
197  ULONG Result;
198 
199  /* Generate the random number */
200  Result = (*Seed * LCG_A + LCG_C) % LCG_M;
201 
202  /* Return it */
203  *Seed = Result;
204  return Result;
205 }
#define LCG_M
Definition: random.c:93
#define LCG_A
Definition: random.c:91
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
unsigned int ULONG
Definition: retypes.h:1
#define LCG_C
Definition: random.c:92

Variable Documentation

◆ RtlpRandomConstantVector

ULONG RtlpRandomConstantVector[128]
static

Definition at line 17 of file random.c.

Referenced by RtlRandom().

◆ RtlpRandomExAuxVarY

ULONG RtlpRandomExAuxVarY = 0x7775fb16
static

Definition at line 89 of file random.c.

Referenced by RtlRandomEx().

◆ RtlpRandomExConstantVector

ULONG RtlpRandomExConstantVector[128]
static

Definition at line 53 of file random.c.

Referenced by RtlRandomEx().