ReactOS 0.4.15-dev-7931-gfd331f1
rand.c File Reference
#include <precomp.h>
#include <ntsecapi.h>
#include <internal/tls.h>
Include dependency graph for rand.c:

Go to the source code of this file.

Functions

int rand (void)
 
void srand (unsigned int seed)
 
int CDECL rand_s (unsigned int *pval)
 

Function Documentation

◆ rand()

int rand ( void  )

Definition at line 10 of file rand.c.

11{
13
14 /* this is the algorithm used by MSVC, according to
15 * http://en.wikipedia.org/wiki/List_of_pseudorandom_number_generators */
16 data->random_seed = data->random_seed * 214013 + 2531011;
17 return (data->random_seed >> 16) & RAND_MAX;
18}
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define RAND_MAX
Definition: stdlib.h:87
thread_data_t * msvcrt_get_thread_data(void)
Definition: tls.c:31

◆ rand_s()

int CDECL rand_s ( unsigned int pval)

Definition at line 33 of file rand.c.

34{
35 BOOLEAN (WINAPI *pSystemFunction036)(PVOID, ULONG); // RtlGenRandom
36 HINSTANCE hadvapi32;
37
38 if (!pval)
39 {
40 _invalid_parameter(NULL,_CRT_WIDE("rand_s"),_CRT_WIDE(__FILE__),__LINE__, 0);
41 *_errno() = EINVAL;
42 return EINVAL;
43 }
44
45 *pval = 0;
46 hadvapi32 = LoadLibraryA("advapi32.dll");
47 if (!hadvapi32)
48 {
49 _invalid_parameter(NULL,_CRT_WIDE("rand_s"),_CRT_WIDE(__FILE__),__LINE__, 0);
50 *_errno() = EINVAL;
51 return EINVAL;
52 }
53
54 pSystemFunction036 = (void*)GetProcAddress(hadvapi32, "SystemFunction036");
55 if (!pSystemFunction036)
56 {
57 _invalid_parameter(NULL,_CRT_WIDE("rand_s"),_CRT_WIDE(__FILE__),__LINE__, 0);
58 *_errno() = EINVAL;
59 FreeLibrary(hadvapi32);
60 return EINVAL;
61 }
62
63 if (!pSystemFunction036(pval, sizeof(*pval)))
64 {
65 _invalid_parameter(NULL,_CRT_WIDE("rand_s"),_CRT_WIDE(__FILE__),__LINE__, 0);
66 *_errno() = EINVAL;
67 FreeLibrary(hadvapi32);
68 return EINVAL;
69 }
70
71 FreeLibrary(hadvapi32);
72 return 0;
73}
#define EINVAL
Definition: acclib.h:90
#define _CRT_WIDE(_String)
Definition: crtdefs.h:55
#define NULL
Definition: types.h:112
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
#define BOOLEAN
Definition: pedump.c:73
void _invalid_parameter(const wchar_t *expression, const wchar_t *function, const wchar_t *file, unsigned int line, uintptr_t pReserved)
Definition: errno.c:137
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
void * PVOID
Definition: typedefs.h:50
uint32_t ULONG
Definition: typedefs.h:59
#define WINAPI
Definition: msvc.h:6

◆ srand()

void srand ( unsigned int  seed)

Definition at line 24 of file rand.c.

25{
27 data->random_seed = seed;
28}