Skip to content

MixMax RNG with variate_generator returns constant values when initialised with seed = 0 #104

Description

@andrjohns

When the mixmax RNG is initialised with a seed of 0 and used with variate_generator, repeated calls always produce the same value:

Reproducible example (here on godbolt):

#include <boost/random.hpp>
#include <iostream>

int main() {
  using boost::normal_distribution;
  using boost::random::uniform_real_distribution;
  using boost::variate_generator;
  using boost::random::mixmax;

  mixmax rng(0);
  variate_generator<mixmax&, normal_distribution<> > norm_rng(rng, normal_distribution<>(5, 10));
  variate_generator<mixmax&, uniform_real_distribution<> > unif_rng(rng, uniform_real_distribution<>(5.0, 10.0));

  for (size_t i = 0; i < 5; ++i) {
    std::cout   << "Normal(5,10): " << norm_rng() << "\n"
                << "Uniform(5,10): " << unif_rng() << "\n";
  }
    std::cout << std::endl;
    return 0;
}

Returns:

Normal(5,10): 5
Uniform(5,10): 5
Normal(5,10): 5
Uniform(5,10): 5
Normal(5,10): 5
Uniform(5,10): 5
Normal(5,10): 5
Uniform(5,10): 5
Normal(5,10): 5
Uniform(5,10): 5

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions