Random.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #pragma once
  2. #include "Betriebssystem.h"
  3. #include "ReferenceCounter.h"
  4. namespace Framework
  5. {
  6. class Datei;
  7. class RandomGenerator : public virtual ReferenceCounter
  8. {
  9. private:
  10. struct random_data
  11. {
  12. int* fptr; /* Front pointer. */
  13. int* rptr; /* Rear pointer. */
  14. int* state; /* Array of state values. */
  15. int rand_type; /* Type of random number generator. */
  16. int rand_deg; /* Degree of random number generator. */
  17. int rand_sep; /* Distance between front and rear. */
  18. int* end_ptr; /* Pointer behind state table. */
  19. };
  20. int randtbl[32];
  21. random_data unsafe_state;
  22. int seed;
  23. int offset;
  24. void srand(int seed);
  25. public:
  26. //! Constructor
  27. //! Creates a new random generator with the seed of the creation
  28. //! time point
  29. DLLEXPORT RandomGenerator();
  30. //! Destructor
  31. DLLEXPORT ~RandomGenerator();
  32. //! Returns a random number between 0 and 1
  33. DLLEXPORT double rand();
  34. //! Initializes the generator with a seed.
  35. //! This method should preferably only be used with seeds returned
  36. //! by getSeed, as the call can otherwise take very long
  37. DLLEXPORT void setSeed(__int64 seed);
  38. //! Returns the current seed with which all further random numbers
  39. //! can be predetermined
  40. DLLEXPORT __int64 getSeed() const;
  41. };
  42. } // namespace Framework