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.

99 lines
1.5 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. vfrandom.c
  5. Abstract:
  6. This module implements support for random number generation needed by the
  7. verifier.
  8. Author:
  9. Adrian J. Oney (adriao) 28-Jun-2000
  10. Environment:
  11. Kernel mode
  12. Revision History:
  13. --*/
  14. #include "vfdef.h"
  15. #ifdef ALLOC_PRAGMA
  16. #pragma alloc_text(INIT, VfRandomInit)
  17. #pragma alloc_text(PAGEVRFY, VfRandomGetNumber)
  18. #endif // ALLOC_PRAGMA
  19. VOID
  20. VfRandomInit(
  21. VOID
  22. )
  23. /*++
  24. Routine Description:
  25. This routine initializes the random number generator, seeing it based on
  26. the startup time of the machine.
  27. Arguments:
  28. None.
  29. Return Value:
  30. None.
  31. --*/
  32. {
  33. }
  34. ULONG
  35. FASTCALL
  36. VfRandomGetNumber(
  37. IN ULONG Minimum,
  38. IN ULONG Maximum
  39. )
  40. /*++
  41. Routine Description:
  42. This routine returns a random number in the range [Minimum, Maximum].
  43. Arguments:
  44. Minimum - Minimum value returnable
  45. Maximum - Maximum value returnable
  46. Return Value:
  47. A random number between Minimum and Maximum
  48. --*/
  49. {
  50. LARGE_INTEGER performanceCounter;
  51. //
  52. // This should be replaced with the algorithm from rtl\random.c
  53. //
  54. KeQueryPerformanceCounter(&performanceCounter);
  55. if (Maximum + 1 == Minimum) {
  56. return performanceCounter.LowPart;
  57. } else {
  58. return (performanceCounter.LowPart % (Maximum - Minimum + 1)) + Minimum;
  59. }
  60. }