James_H has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am trying to generate a lognormal sample with a given mean and std deviation using the gsl function - gsl_ran_lognormal.
Can someone please help?
Thanks, James.
Here is my feeble attempt...
use Math::GSL::Randist qw/:all/; use Math::GSL::RNG; my $rng = Math::GSL::RNG->new; my $random_number = $rng->get(1); my $x = gsl_ran_lognormal($random_number, 0.1, 0.2); print "$x\n";

Replies are listed 'Best First'.
Re: GSL lognormal random
by roboticus (Chancellor) on Mar 09, 2011 at 13:03 UTC

    James_H:

    I looked over the docs, and the code looks reasonable. What problem are you having? Is the program not compiling, or does it give an unreasonable value, or some other problem?

    I'm not really interested in installing the modules so I can try out your code, nor do I know what you want, nor do I know what it's giving you. If you add a bit more information to your post, someone may be able to help.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: GSL lognormal random
by Khen1950fx (Canon) on Mar 09, 2011 at 13:43 UTC
    This is untested due to a borked installation, but I would try it in a form something like this:
    #!/usr/bin/perl use strict; use warnings; use Math::GSL::Randist qw/:all/; use Math::GSL::RNG; my $rng = Math::GSL::RNG->new; my $num = $rng->raw(1); my $x = Math::GSL::gsl_ran_lognormal::new( $num, 0.1, 0.2); print "$x\n";

      Thank you to both. Here is codes that works...

      Regards, James

      use Math::GSL::Randist qw/:all/; use Math::GSL::RNG; my $rng = Math::GSL::RNG->new; my $random_numbers = $rng->raw(); my $x = gsl_ran_lognormal($random_numbers, 0.1, 0.2); print "$x\n";