Is it modern C++ to use srand to set random seed?

后端 未结 3 1703
慢半拍i
慢半拍i 2021-02-13 05:07

For code that uses std::random_shuffle, I need to set a random seed so that the pseudorandom sequences produced vary in each program run.

The code example h

3条回答
  •  忘掉有多难
    2021-02-13 05:11

    If you really care about accuracy, quality and diversity of the ways to generate random numbers, I would highly suggest to consider using the famous Gnu Scientific Library (GSL)

    This allows real uniform generation and various algorithms for the best. See here.

    Specially this and this describes the available algorithms :

    — gsl_rng_mt19937
    — gsl_rng_taus
    — gsl_rng_taus2
    — gsl_rng_gfsr4
    ...
    

    EDIT : Also boost::random should be a good alternative considering the GPLness of GSL (but I never dealed with it...).

提交回复
热议问题