RANDOM.H 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /* $Header: /CounterStrike/RANDOM.H 1 3/03/97 10:25a Joe_bostic $ */
  15. /***********************************************************************************************
  16. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  17. ***********************************************************************************************
  18. * *
  19. * Project Name : Command & Conquer *
  20. * *
  21. * File Name : RANDOM.H *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : 02/27/96 *
  26. * *
  27. * Last Update : February 27, 1996 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  32. #ifndef RANDOM_H
  33. #define RANDOM_H
  34. /**********************************************************************
  35. ** Enable this define to turn on the random # counters. This must not
  36. ** be defined for the release version, or saved games won't work!
  37. */
  38. //#define RANDOM_COUNT
  39. /*
  40. ** This class functions like a 'magic' int value that returns a random number
  41. ** every time it is read. To set the "random seed" for this, just assign a number
  42. ** to the object (just as you would if it were a true 'int' value). Take note that although
  43. ** this class will return an 'int', the actual significance of the random number is
  44. ** limited to 15 bits (0..32767).
  45. */
  46. class RandomClass {
  47. public:
  48. RandomClass(unsigned seed=0);
  49. operator int(void) {return(operator()());};
  50. int operator() (void);
  51. int operator() (int minval, int maxval);
  52. enum {
  53. SIGNIFICANT_BITS=15 // Random number bit significance.
  54. };
  55. unsigned long Seed;
  56. #ifdef RANDOM_COUNT
  57. unsigned long Count1;
  58. unsigned long Count2;
  59. #endif
  60. protected:
  61. /*
  62. ** Internal working constants that are used to generate the next
  63. ** random number.
  64. */
  65. enum {
  66. MULT_CONSTANT=0x41C64E6D, // K multiplier value.
  67. ADD_CONSTANT=0x00003039, // K additive value.
  68. THROW_AWAY_BITS=10 // Low bits to throw away.
  69. };
  70. };
  71. #endif