Removing more useless ->{} notation
[Math-GSL.git] / RNG.i
blobd95c3da076b2186de5278884d4b77a134b5a8e80
1 %module "Math::GSL::RNG"
2 %{
3 #include "gsl/gsl_rng.h"
4 %}
5 %import "gsl/gsl_types.h"
7 %include "gsl/gsl_rng.h"
9 FILE *fopen(char *, char *);
10 int fclose(FILE *);
12 %perlcode %{
13 @EXPORT_OK = qw/ fopen fclose
14 gsl_rng_alloc gsl_rng_set gsl_rng_get gsl_rng_free gsl_rng_memcpy
15 gsl_rng_fwrite gsl_rng_fread gsl_rng_clone gsl_rng_max gsl_rng_min
16 gsl_rng_name gsl_rng_size gsl_rng_state gsl_rng_print_state
17 $gsl_rng_default $$gsl_rng_knuthran $$gsl_rng_ran0 $gsl_rng_borosh13
18 $gsl_rng_coveyou $gsl_rng_cmrg $gsl_rng_fishman18 $gsl_rng_fishman20 $gsl_rng_fishman2x
19 $gsl_rng_gfsr4 $gsl_rng_knuthran $gsl_rng_knuthran2 $gsl_rng_knuthran2002 $gsl_rng_lecuyer21
20 $gsl_rng_minstd $gsl_rng_mrg $gsl_rng_mt19937 $gsl_rng_mt19937_1999 $gsl_rng_mt19937_1998
21 $gsl_rng_r250 $gsl_rng_ran0 $gsl_rng_ran1 $gsl_rng_ran2 $gsl_rng_ran3
22 $gsl_rng_rand $gsl_rng_rand48 $gsl_rng_random128_bsd $gsl_rng_random128_gli $gsl_rng_random128_lib
23 $gsl_rng_random256_bsd $gsl_rng_random256_gli $gsl_rng_random256_lib $gsl_rng_random32_bsd
24 $gsl_rng_random32_glib $gsl_rng_random32_libc $gsl_rng_random64_bsd $gsl_rng_random64_glib
25 $gsl_rng_random64_libc $gsl_rng_random8_bsd $gsl_rng_random8_glibc $gsl_rng_random8_libc5
26 $gsl_rng_random_bsd $gsl_rng_random_glibc2 $gsl_rng_random_libc5 $gsl_rng_randu
27 $gsl_rng_ranf $gsl_rng_ranlux $gsl_rng_ranlux389 $gsl_rng_ranlxd1 $gsl_rng_ranlxd2 $gsl_rng_ranlxs0
28 $gsl_rng_ranlxs1 $gsl_rng_ranlxs2 $gsl_rng_ranmar $gsl_rng_slatec $gsl_rng_taus $gsl_rng_taus2
29 $gsl_rng_taus113 $gsl_rng_transputer $gsl_rng_tt800 $gsl_rng_uni $gsl_rng_uni32 $gsl_rng_vax
30 $gsl_rng_waterman14 $gsl_rng_zuf
32 %EXPORT_TAGS = ( all => [ @EXPORT_OK ] );
34 sub new {
35 my ($class, $type, $seed) = @_;
36 $type ||= $gsl_rng_default;
37 $seed ||= int 100*rand;
39 my $self = {};
40 my $rng = gsl_rng_alloc($type);
41 gsl_rng_set($rng, $seed);
43 $self->{_rng} = $rng;
44 bless $self, $class;
47 sub copy {
48 my ($self) = @_;
49 my $copy = Math::GSL::RNG->new;
50 $copy->{_rng} = gsl_rng_clone($self->{_rng});
52 return $copy;
55 sub free {
56 my ($self) = @_;
57 gsl_rng_free($self->{_rng});
59 sub name {
60 my ($self) = @_;
61 gsl_rng_name($self->{_rng});
63 sub get {
64 my ($self) = @_;
66 gsl_rng_get($self->{_rng});
69 __END__
71 =head1 NAME
73 Math::GSL::RNG - Random Number Generators
75 =head1 SYNOPSIS
77 use Math::GSL::RNG qw/:all/;
79 =head1 DESCRIPTION
81 Here is a list of all the functions included in this module :
83 gsl_rng_alloc gsl_rng_set gsl_rng_get gsl_rng_free gsl_rng_memcpy
84 gsl_rng_fwrite gsl_rng_fread gsl_rng_clone gsl_rng_max gsl_rng_min
85 gsl_rng_name gsl_rng_size gsl_rng_state gsl_rng_print_state
88 This module also contains the following constants :
90 $gsl_rng_default $$gsl_rng_knuthran $$gsl_rng_ran0 $gsl_rng_borosh13
91 $gsl_rng_coveyou $gsl_rng_cmrg $gsl_rng_fishman18 $gsl_rng_fishman20 $gsl_rng_fishman2x
92 $gsl_rng_gfsr4 $gsl_rng_knuthran $gsl_rng_knuthran2 $gsl_rng_knuthran2002 $gsl_rng_lecuyer21
93 $gsl_rng_minstd $gsl_rng_mrg $gsl_rng_mt19937 $gsl_rng_mt19937_1999 $gsl_rng_mt19937_1998
94 $gsl_rng_r250 $gsl_rng_ran0 $gsl_rng_ran1 $gsl_rng_ran2 $gsl_rng_ran3
95 $gsl_rng_rand $gsl_rng_rand48 $gsl_rng_random128_bsd $gsl_rng_random128_gli $gsl_rng_random128_lib
96 $gsl_rng_random256_bsd $gsl_rng_random256_gli $gsl_rng_random256_lib $gsl_rng_random32_bsd
97 $gsl_rng_random32_glib $gsl_rng_random32_libc $gsl_rng_random64_bsd $gsl_rng_random64_glib
98 $gsl_rng_random64_libc $gsl_rng_random8_bsd $gsl_rng_random8_glibc $gsl_rng_random8_libc5
99 $gsl_rng_random_bsd $gsl_rng_random_glibc2 $gsl_rng_random_libc5 $gsl_rng_randu
100 $gsl_rng_ranf $gsl_rng_ranlux $gsl_rng_ranlux389 $gsl_rng_ranlxd1 $gsl_rng_ranlxd2 $gsl_rng_ranlxs0
101 $gsl_rng_ranlxs1 $gsl_rng_ranlxs2 $gsl_rng_ranmar $gsl_rng_slatec $gsl_rng_taus $gsl_rng_taus2
102 $gsl_rng_taus113 $gsl_rng_transputer $gsl_rng_tt800 $gsl_rng_uni $gsl_rng_uni32 $gsl_rng_vax
103 $gsl_rng_waterman14 $gsl_rng_zuf
105 For more informations on the functions, we refer you to the GSL offcial documentation: http://www.gnu.org/software/gsl/manual/html_node/
106 Tip : search on google: site:http://www.gnu.org/software/gsl/manual/html_node/ name_of_the_function_you_want
108 =head1 EXAMPLES
110 The following example will print out a list a random integers between certain
111 minimum and maximum values. The command line arguments are first the number of
112 random numbers wanted, the minimum and then maximum. The defaults are 10, 0 and
113 100, respectively.
115 use Math::GSL::RNG qw/:all/;
116 my $seed = int rand(100);
117 my $rng = Math::GSL::RNG->new($gsl_rng_knuthran, $seed );
118 my ($num,$min,$max) = @ARGV;
119 $num ||= 10;
120 $min ||= 0;
121 $max ||= 100;
122 print join "\n", map { $min + $rng->get % ($max-$min+1) } (1..$num);
123 print "\n";
125 The C<$seed> argument is optional but encouraged. This program is available in
126 the B<examples/> directory that comes with the source of this module.
128 If you would like a series of random non-integer numbers, then you can generate one "scaling factor"
129 and multiple by that, such as
131 use Math::GSL::RNG qw/:all/;
132 my $scale= rand(10);
133 my $seed = int rand(100);
134 my $rng = Math::GSL::RNG->new($gsl_rng_knuthran, $seed );
135 my ($num,$min,$max) = (10,0,100);
136 print join "\n", map { $scale*($min + $rng->get % ($max-$min+1)) } (1..$num);
137 print "\n";
139 =head1 AUTHOR
141 Jonathan Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com>
143 =head1 COPYRIGHT AND LICENSE
145 Copyright (C) 2008 Jonathan Leto and Thierry Moisan
147 This program is free software; you can redistribute it and/or modify it
148 under the same terms as Perl itself.
150 =cut