mirror of
https://github.com/reactos/reactos.git
synced 2025-04-21 12:40:33 +00:00

Imported from https://www.nuget.org/packages/Microsoft.Windows.SDK.CRTSource/10.0.22621.3 License: MIT
28 lines
612 B
C++
28 lines
612 B
C++
//
|
|
// rand.cpp
|
|
//
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
//
|
|
// Defines rand(), which generates psuedorandom numbers.
|
|
//
|
|
#include <corecrt_internal.h>
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
// Seeds the random number generator with the provided integer.
|
|
extern "C" void __cdecl srand(unsigned int const seed)
|
|
{
|
|
__acrt_getptd()->_rand_state = seed;
|
|
}
|
|
|
|
|
|
|
|
// Returns a pseudorandom number in the range [0,32767].
|
|
extern "C" int __cdecl rand()
|
|
{
|
|
__acrt_ptd* const ptd = __acrt_getptd();
|
|
|
|
ptd->_rand_state = ptd->_rand_state * 214013 + 2531011;
|
|
return (ptd->_rand_state >> 16) & RAND_MAX;
|
|
}
|