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.
14
extern
"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].
22
extern
"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
}
__cdecl
#define __cdecl
Definition:
accygwin.h:79
corecrt_internal.h
__acrt_getptd
__acrt_ptd *__cdecl __acrt_getptd(void)
Definition:
per_thread_data.cpp:298
ptd
_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
RAND_MAX
#define RAND_MAX
Definition:
stdlib.h:87
srand
void __cdecl srand(unsigned int const seed)
Definition:
rand.cpp:14
rand
int __cdecl rand()
Definition:
rand.cpp:22
__acrt_ptd
Definition:
corecrt_internal.h:865
__acrt_ptd::_rand_state
unsigned int _rand_state
Definition:
corecrt_internal.h:876
sdk
lib
ucrt
stdlib
rand.cpp
Generated on Sun Mar 23 2025 06:14:41 for ReactOS by
1.9.6