Der neue Dienst "GitLab am KIT" ist unter gitlab.kit.edu erreichbar.

Skip to content
  • we7765's avatar
    [FIX] (libtsxx): fix random number sequence · 699c7722
    we7765 authored
    Multiple calls to ts::rnd::dugauss() resulted in identical sequences of random
    numbers.
    
    Issue regarding random number generator in libtsxx
    ==================================================
    
    Location: src/libs/libtsxx/random.cc
    
    The function ts::rnd::dugauss() allocates a GSL random number generator and
    immediately seeds it. The seeding operation is required, since the default
    seed is a constant, which would result in identical sequences. Function
    ts::rnd::dugauss() uses the current system time as returned by function time()
    as a seed value. Unfortunately, if ts::rnd::dugauss() is called several times
    during the same second, this also will result in identical sequences.
    
    Currently ts::rnd::dugauss() is only used by src/ts/wf/noisymize.cc and by the
    filter GaussianNoise in libtsxx.
    
    The appropriate solution appears to be:
    - encapsulate the GSL randon number generator in a class object, just like is
      provided in tfxx::numeric::RNGgaussian
    - use a static variable of this class type in ts::rnd::dugauss()
      this variable will be initialized only once upon the first call to the
      function
    - the destructor is guaranteed to be called after termination of the program,
      such that the destructor is able to properly call gsl_rng_free
    699c7722