public inbox for gsl-discuss@sourceware.org
 help / color / mirror / Atom feed
From: "Jari Häkkinen" <jari@chiralcomp.com>
To: Brian Gough <bjg@network-theory.co.uk>
Cc: gsl-discuss@sources.redhat.com
Subject: Re: rng question
Date: Fri, 09 Dec 2005 13:49:00 -0000	[thread overview]
Message-ID: <43998B68.8040903@chiralcomp.com> (raw)
In-Reply-To: <17303.16636.732007.363616@hp2.network-theory.co.uk>

[-- Attachment #1: Type: text/plain, Size: 1134 bytes --]

No, the attached program does not return from the call to 
gsl_rng_uniform_int.

The problem shows up on my powermac running MacOSX 10.4.3 with gcc 
version powerpc-apple-darwin8-gcc-4.0.0 (GCC) 4.0.0 20041026 (Apple 
Computer, Inc. build 4061).
I compile GSL from CVS (20051208 = today) with with flags -NDEBUG -O2. 
The test program is compiled with a plain 'gcc -o rnd_test rnd_test.c 
-lgsl'.

Now, I also run the test program on a SuSE based machine, and the call 
fails with an floating point exception as expected.


Jari


Brian Gough wrote:
> Jari Häkkinen writes:
>  > According to the documentation gsl_rng_max(rng_ returns the maximum 
>  > random number the underlying rng can give, and 
>  > gsl_rng_uniform_int(rng,gsl_rng_max(rng)) will return 
>  > [0,gsl_rng_max(rng)-1]. This will not give the maximum number from the 
>  > underlying generator, so I tried 
>  > gsl_rng_uniform_int(rng,gsl_rng_max(rng)+1) but this call does not 
>  > return (since the second argument becomes 0).
> 
> Doesn't it give an exception? (due to division by zero in the expression scale = range / n;)
> What platform are you using?
> 

[-- Attachment #2: rnd_test.c --]
[-- Type: text/plain, Size: 280 bytes --]

#include <gsl/gsl_rng.h>

int main(const int argc,const char* argv[])
{
	gsl_rng_env_setup();
	gsl_rng* rng=gsl_rng_alloc(gsl_rng_default);
	unsigned long max=gsl_rng_max(rng);
	printf("%u\n",max+1);
	unsigned long number=gsl_rng_uniform_int(rng,max+1);
	printf("%u\n",number);
}

  reply	other threads:[~2005-12-09 13:49 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-07 10:25 Jari Häkkinen
2005-12-07 20:07 ` Brian Gough
2005-12-09 13:49   ` Jari Häkkinen [this message]
2005-12-17 16:50     ` Brian Gough
2005-12-17 23:58       ` Jari Häkkinen
2008-08-03 23:32 RNG question Robert G. Brown
2008-08-05  9:05 ` Fabian Bastin
2008-08-08 11:12 ` Brian Gough
2008-08-08 12:33   ` Robert G. Brown
2008-08-11 20:47     ` Brian Gough
2008-08-18 21:12     ` Robert G. Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=43998B68.8040903@chiralcomp.com \
    --to=jari@chiralcomp.com \
    --cc=bjg@network-theory.co.uk \
    --cc=gsl-discuss@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).