vendredi 15 février 2019

C++ vs C# generating the same sequence of random numbers after a reset

In c# i wrote a function that generates a next random number in the sequence using a random number generator which i seeded with a special value in the constructor:

    public randomS(int number = DefaultValue) : base(number)
    {
        seed = p;
        random = new Random((int) seed);

    }
    protected int GenerateNextSequence()
    {
       return random.Next(MIN_VALUE, MAX_VALUE);
    }

The user can then call a reset function to reset this sequence where i seed the random number generator again with the same value and the GenerateNextSequence will start generating the same numbers that it generated before the reset:

public override void ResetSequence()
    {
        random = new Random((int) seed);
        state = true;
    }

I would like to do the similar thing in C++. In not sure if its possible to do something like this in C++. If there is, could anyone help me translate this code into c++?




Aucun commentaire:

Enregistrer un commentaire