bug-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-gsl] show-stopping gsl_rng_set bug (with workaround)


From: Havona Studios
Subject: [Bug-gsl] show-stopping gsl_rng_set bug (with workaround)
Date: Thu, 15 Mar 2012 06:54:06 -0600
User-agent: Mutt/1.5.21 (2010-09-15)

The minstd, ran0, ran1, ran2 algorithms are show-stoppingly buggy when
unsigned long is used to seed.  Workaround is to use unsigned int.

minstd and ran0 are not producing uniform floats/doubles (compare
result with default) and go into 100% CPU loop on uniform_int, while
ran1 and ran2 will simply segfault on either function call.

default and all others work as expected/documented.

rng_test.c:

#include <gsl/gsl_rng.h>

int
main (void)
{
  FILE *urandom = fopen ("/dev/urandom", "r");
  unsigned int u_seed;
  fread (&u_seed, 1, sizeof u_seed, urandom);
  unsigned long lu_seed;
  fread (&lu_seed, 1, sizeof lu_seed, urandom);
  fclose (urandom);

  gsl_rng_env_setup ();
  gsl_rng *rng = gsl_rng_alloc (gsl_rng_default);

  gsl_rng_set (rng, u_seed);
  printf ("seed:\t\t%u\n", u_seed);
  printf ("uniform:\t%f\n", gsl_rng_uniform (rng));
  printf ("uniform_int:\t%i\n", gsl_rng_uniform_int (rng, 2));

  gsl_rng_set (rng, lu_seed);
  printf ("seed:\t\t%lu\n", lu_seed);
  printf ("uniform:\t%f\n", gsl_rng_uniform (rng));
  printf ("uniform_int:\t%i\n", gsl_rng_uniform_int (rng, 2));

  exit (EXIT_SUCCESS);
}

$ gcc -lgsl -lgslcblas -o rng_test rng_test.c

$ ./rng_test                     && echo success
$ GSL_RNG_TYPE=minstd ./rng_test || echo hang 
$ GSL_RNG_TYPE=ran0 ./rng_test   || echo hang 
$ GSL_RNG_TYPE=ran1 ./rng_test   || echo segfault
$ GSL_RNG_TYPE=ran2 ./rng_test   || echo segfault

$ pacman -Q gcc gsl
gcc 4.6.3-1
gsl 1.15-2
$ uname -srmp
Linux 3.2.9-1-ARCH x86_64 Intel(R) Core(TM) i7-2860QM CPU @ 2.50GHz




reply via email to

[Prev in Thread] Current Thread [Next in Thread]