ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

rand.c
Go to the documentation of this file.
00001 /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
00002 #include <precomp.h>
00003 #include <ntsecapi.h>
00004 #include <internal/tls.h>
00005 
00006 /*
00007  * @implemented
00008  */
00009 int
00010 rand(void)
00011 {
00012     thread_data_t *data = msvcrt_get_thread_data();
00013 
00014     /* this is the algorithm used by MSVC, according to
00015      * http://en.wikipedia.org/wiki/List_of_pseudorandom_number_generators */
00016     data->random_seed = data->random_seed * 214013 + 2531011;
00017     return (data->random_seed >> 16) & RAND_MAX;
00018 }
00019 
00020 /*
00021  * @implemented
00022  */
00023 void
00024 srand(unsigned int seed)
00025 {
00026     thread_data_t *data = msvcrt_get_thread_data();
00027     data->random_seed = seed;
00028 }
00029 
00030  /*********************************************************************
00031   *              rand_s (MSVCRT.@)
00032   */
00033 int CDECL rand_s(unsigned int *pval)
00034 {
00035     BOOLEAN (WINAPI *pSystemFunction036)(PVOID, ULONG); // RtlGenRandom
00036     HINSTANCE hadvapi32 = LoadLibraryA("advapi32.dll");    
00037     pSystemFunction036 = (void*)GetProcAddress(hadvapi32, "SystemFunction036");
00038 #if 1
00039     if (!pval || (pSystemFunction036 && !pSystemFunction036(pval, sizeof(*pval))))
00040     {
00041         _invalid_parameter(NULL,_CRT_WIDE("rand_s"),_CRT_WIDE(__FILE__),__LINE__, 0);
00042         *_errno() = EINVAL;
00043         return EINVAL;
00044     }
00045 #endif
00046     if(hadvapi32) FreeLibrary(hadvapi32);
00047     return 0;
00048 }

Generated on Sat May 26 2012 04:35:27 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.