Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
5.0 KiB

  1. #pragma warning( disable: 4001 4201 4214 4514 )
  2. #include <windows.h> // needed for ULONG and CriticalSection support
  3. #pragma warning( disable: 4001 4201 4214 4514 )
  4. /////////////////////////////////////////////////////////////////////////////
  5. // //
  6. // randpeak.h -- Exported interface for randpeak.c //
  7. // //
  8. // While this header is targeted for Win32, the code //
  9. // in randpeak.c is portable provided the following: //
  10. // //
  11. // ULONG is an unsigned 32-bit data type //
  12. // and BOOL is an integral boolean type //
  13. // //
  14. // Two's complement wraparound (mod 2^32) //
  15. // occurs on addition and multiplication //
  16. // where result is greater than (2^32-1) //
  17. // //
  18. // If _MT or MULTITHREADED is defined, the //
  19. // definition and support of critical //
  20. // section primitives: //
  21. // //
  22. // CRITICAL_SECTION data type //
  23. // InitializeCriticalSection function //
  24. // EnterCriticalSection function //
  25. // LeaveCriticalSection function //
  26. // //
  27. // Author: Tom McGuire (tommcg), 03/29/94 //
  28. // //
  29. // (C) Copyright 1994, Microsoft Corporation //
  30. // //
  31. /////////////////////////////////////////////////////////////////////////////
  32. #if ( defined( _MT ) && ! defined( MULTITHREADED ))
  33. #define MULTITHREADED 1 // compile multi-threaded support
  34. #endif
  35. ULONG BitReverse32( ULONG ulNumber ); // 31:0 -> 0:31
  36. void SeedRandom32( ULONG ulSeed ); // must call first, non-reentrant
  37. ULONG Random32( void ); // linear distribution 0<n<2^32-1
  38. ULONG RandomInRange( ULONG ulMinInclusive, // Random32() mod Range
  39. ULONG ulMaxInclusive );
  40. ULONG RandomPeaked( ULONG ulMaxInclusive,
  41. ULONG ulPeakFrequency,
  42. ULONG ulPeakWidth,
  43. ULONG ulPeakDensity,
  44. ULONG ulPeakDecay );
  45. /////////////////////////////////////////////////////////////////////////////
  46. // //
  47. // | Peaked Distribution | //
  48. // |_ | //
  49. // | \ | //
  50. // | \ _ | //
  51. // | \ / \ _ | //
  52. // | \ / \ / \ _ | //
  53. // | \ / \ / \ / \ _| //
  54. // | \_____/ \________/ \__ __/ \____________/ | //
  55. // |_______________________________________________________________| //
  56. // 0 P 2P nP Max //
  57. // //
  58. // The center of each peak occurs at ulPeakFreq intervals starting //
  59. // from zero, and the tops of the peaks are linear-distributed across //
  60. // ulPeakWidth (ie, +/- ulPeakWidth/2). ulPeakDensity controls the //
  61. // slope of the distribution off each peak with higher numbers causing //
  62. // steeper slopes (and hence wider, lower valleys). ulPeakDecay //
  63. // controls the declining peak-to-peak slope with higher numbers //
  64. // causing higher peaks near zero and lower peaks toward ulMax. //
  65. // Note that ulPeakDensity and ulPeakDecay are computationally //
  66. // expensive with higher values (they represent internal iteration //
  67. // counts), so moderate numbers such as 3-5 for ulPeakDensity and //
  68. // 1-2 for ulPeakDecay are recommended. //
  69. // //
  70. /////////////////////////////////////////////////////////////////////////////