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.

64 lines
1.5 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998, 1999, 2000
  4. *
  5. * TITLE: RANDGEN.H
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 1/13/1999
  12. *
  13. * DESCRIPTION: Random number generator class
  14. *
  15. *******************************************************************************/
  16. #ifndef __RANDGEN_H_INCLUDED
  17. #define __RANDGEN_H_INCLUDED
  18. #include <windows.h>
  19. #ifndef RECT_WIDTH
  20. #define RECT_WIDTH(rc) (rc.right-rc.left)
  21. #endif
  22. #ifndef RECT_HEIGHT
  23. #define RECT_HEIGHT(rc) (rc.bottom-rc.top)
  24. #endif
  25. class CRandomNumberGen
  26. {
  27. private:
  28. long m_nOldRand;
  29. public:
  30. CRandomNumberGen( long nSeed = GetTickCount() )
  31. : m_nOldRand(nSeed)
  32. {
  33. }
  34. int Generate(void)
  35. {
  36. return(((m_nOldRand = m_nOldRand * 214013L + 2531011L) >> 16) & 0x7fff);
  37. }
  38. int Generate( int nMin, int nMax )
  39. {
  40. if (nMax - nMin == 0)
  41. return nMin;
  42. return(Generate() % (nMax - nMin)) + nMin;
  43. }
  44. int Generate( int nMax )
  45. {
  46. return (Generate( 0, nMax ));
  47. }
  48. RECT Generate( int nWidth, int nHeight, const RECT &rcRange )
  49. {
  50. RECT rcReturn;
  51. rcReturn.left = rcRange.left + Generate( 0, RECT_WIDTH(rcRange)-nWidth );
  52. rcReturn.top = rcRange.top + Generate( 0, RECT_HEIGHT(rcRange)-nHeight );
  53. rcReturn.right = rcReturn.left + nWidth;
  54. rcReturn.bottom = rcReturn.top + nHeight;
  55. return rcReturn;
  56. }
  57. };
  58. #endif