Reactos
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}