ReactOS 0.4.16-dev-852-gcfcc8d8
rand.cpp
Go to the documentation of this file.
1//
2// rand.cpp
3//
4// Copyright (c) Microsoft Corporation. All rights reserved.
5//
6// Defines rand(), which generates psuedorandom numbers.
7//
8#include <corecrt_internal.h>
9#include <stdlib.h>
10
11
12
13// Seeds the random number generator with the provided integer.
14extern "C" void __cdecl srand(unsigned int const seed)
15{
16 __acrt_getptd()->_rand_state = seed;
17}
18
19
20
21// Returns a pseudorandom number in the range [0,32767].
22extern "C" int __cdecl rand()
23{
24 __acrt_ptd* const ptd = __acrt_getptd();
25
26 ptd->_rand_state = ptd->_rand_state * 214013 + 2531011;
27 return (ptd->_rand_state >> 16) & RAND_MAX;
28}
#define __cdecl
Definition: accygwin.h:79
__acrt_ptd *__cdecl __acrt_getptd(void)
_In_ size_t const _In_ int _In_ bool const _In_ unsigned const _In_ __acrt_rounding_mode const _Inout_ __crt_cached_ptd_host & ptd
Definition: cvt.cpp:355
#define RAND_MAX
Definition: stdlib.h:87
void __cdecl srand(unsigned int const seed)
Definition: rand.cpp:14
int __cdecl rand()
Definition: rand.cpp:22
unsigned int _rand_state