File: Random.xs

package info (click to toggle)
libmath-random-perl 0.75-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 316 kB
  • sloc: ansic: 1,443; perl: 1,057; makefile: 8
file content (236 lines) | stat: -rw-r--r-- 3,703 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#ifdef __cplusplus
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#ifdef __cplusplus
}
#endif

#include "randlib.h"
#include "helper.h"

#define PERL_VERSION_ATLEAST(a,b,c)                            \
  (PERL_REVISION > (a)                                         \
   || (PERL_REVISION == (a)                                    \
       && (PERL_VERSION > (b)                                  \
           || (PERL_VERSION == (b) && PERL_SUBVERSION >= (c)))))

#if PERL_VERSION_ATLEAST (5,8,1)
/* For whatever reason, the random seeds need to be in 1..2^30; the below will
 * be uniformly distributed assuming the seed value is uniformly distributed.
 *
 * This approach isn't cryptographically secure. Consider using /dev/random
 * or Math::TrulyRandom to get some real entropy.
 */
#define Perl_get_seed (long)(Perl_seed(aTHX) % 1073741824L)
#else
/* If we don't support seeds, return 0 so we can fall back to localtime for
 * default seeding. There's a chance Perl_seed will return 0 and mask this,
 * but in that case the data should still be "random enough" anyway.
 */
#define Perl_get_seed 0L
#endif /* Perl_seed */

MODULE = Math::Random		PACKAGE = Math::Random		

long
get_seed()
       CODE:
       RETVAL = Perl_get_seed;
       OUTPUT:
       RETVAL

double
genbet (aa,bb)
	double  aa
	double  bb

double
genchi (df)
	double  df

double
genexp (av)
	double  av

double
genf (dfn,dfd)
	double  dfn
	double  dfd

double
gengam (a,r)
	double  a
	double  r

int
psetmn (p)
	long  p

int
pgenmn ()
	PROTOTYPE:

int
rspriw (size)
	long  size

int
rsprfw (size)
	long  size

void
svprfw (index,value)
	long  index
	double  value

void
pgnmul (n,ncat)
	long  n
	long  ncat

long
gvpriw (index)
	long  index

double
gennch (df,xnonc)
	double  df
	double  xnonc

double
gennf (dfn,dfd,xnonc)
	double  dfn
	double  dfd
	double  xnonc

double
gennor (av,sd)
	double  av
	double  sd

void
pgnprm (n)
	long  n
	PROTOTYPE: $

double
genunf (low,high)
	double  low
	double  high

long
ignpoi (mu)
	double  mu

long
ignuin (low,high)
	long  low
	long  high

long
ignnbn (n,p)
	long  n
	double  p

long
ignbin (n,pp)
	long  n
	double  pp

void
phrtsd (phrase)
	char *  phrase
	PROTOTYPE: $
	PREINIT:
	long  newseed1;
	long  newseed2;
	PPCODE:
	phrtsd(phrase,&newseed1,&newseed2);
	EXTEND(sp, 2);
	PUSHs(sv_2mortal(newSViv(newseed1)));
	PUSHs(sv_2mortal(newSViv(newseed2)));

void
random_get_seed ()
	PROTOTYPE:
	PREINIT:
	long  newseed1;
	long  newseed2;
	PPCODE:
	getsd(&newseed1,&newseed2);
	EXTEND(sp, 2);
	PUSHs(sv_2mortal(newSViv(newseed1)));
	PUSHs(sv_2mortal(newSViv(newseed2)));

void
salfph (phrase)
	char *  phrase
	PROTOTYPE: $

void
setall (iseed1,iseed2)
	long  iseed1
	long  iseed2
	PROTOTYPE: $$


void
random_advance_state (k)
    long  k
    CODE:
    if ( k < 0 )
        croak("incorrect value for k; must be >=0");
    advnst(k);

void
random_init_generator (isdtyp)
    long  isdtyp
    CODE:
    if ( isdtyp != -1 && isdtyp != 0 && isdtyp != 1)
        croak("incorrect value for isdtyp; must be -1, 0, or 1");
    initgn(isdtyp);

void
random_set_antithetic (qvalue)
    long  qvalue
    CODE:
    setant(qvalue);

long
random_get_generator_num ()
    PREINIT:
      long old_g;
    CODE:
      gscgn(0, &old_g);
      RETVAL = old_g;
    OUTPUT:
      RETVAL

long
random_set_generator_num ( g)
      long g
    PREINIT:
      long old_g;
    CODE:
      if ( g < 1 || g > 32 )
        croak("incorrect value for 'g'; must be 1 <= g <= 32");
      gscgn(0, &old_g);
      RETVAL = old_g;
      gscgn(1, &g);
    OUTPUT:
      RETVAL

long
random_integer ()
    CODE:
      RETVAL = ignlgi();
    OUTPUT:
      RETVAL

double
gvprfw (index)
	long  index