#pragma once

#include "OperatingSystem.h"
#include "ReferenceCounter.h"

namespace Framework
{
    class File;

    class RandomGenerator : public virtual ReferenceCounter
    {
    private:
        struct random_data
        {
            int* fptr;     /* Front pointer.  */
            int* rptr;     /* Rear pointer.  */
            int* state;    /* Array of state values.  */
            int rand_type; /* Type of random number generator.  */
            int rand_deg;  /* Degree of random number generator.  */
            int rand_sep;  /* Distance between front and rear.  */
            int* end_ptr;  /* Pointer behind state table.  */
        };

        int randtbl[32];
        random_data unsafe_state;
        int seed;
        int offset;

        void srand(int seed);

    public:
        //! Constructor
        //! Creates a new random generator with the seed of the creation
        //! time point
        DLLEXPORT RandomGenerator();
        //! Destructor
        DLLEXPORT ~RandomGenerator();
        //! Returns a random number between 0 and 1
        DLLEXPORT double rand();
        //! Initializes the generator with a seed.
        //! This method should preferably only be used with seeds returned
        //! by getSeed, as the call can otherwise take very long
        DLLEXPORT void setSeed(__int64 seed);
        //! Returns the current seed with which all further random numbers
        //! can be predetermined
        DLLEXPORT __int64 getSeed() const;
    };
} // namespace Framework