Random.xs

filter: Statementstmt 70.8% 17 / 24 Branchbran 55.0% 11 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 63.6% 28 / 44 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« randlib.c ↑ Summary helper.c »
1 #ifdef __cplusplus
2 extern "C" {
3 #endif
4 #include "EXTERN.h"
5 #include "perl.h"
6 #include "XSUB.h"
7 #ifdef __cplusplus
8 }
9 #endif
10  
11 #include "randlib.h"
12 #include "helper.h"
13  
14 #define PERL_VERSION_ATLEAST(a,b,c) \
15 (PERL_REVISION > (a) \
16 || (PERL_REVISION == (a) \
17 && (PERL_VERSION > (b) \
18 || (PERL_VERSION == (b) && PERL_SUBVERSION >= (c)))))
19  
20 #if PERL_VERSION_ATLEAST (5,8,1)
21 /* For whatever reason, the random seeds need to be in 1..2^30; the below will
22 * be uniformly distributed assuming the seed value is uniformly distributed.
23 *
24 * This approach isn't cryptographically secure. Consider using /dev/random
25 * or Math::TrulyRandom to get some real entropy.
26 */
27 #define Perl_get_seed (long)(Perl_seed(aTHX) % 1073741824L)
28 #else
29 /* If we don't support seeds, return 0 so we can fall back to localtime for
30 * default seeding. There's a chance Perl_seed will return 0 and mask this,
31 * but in that case the data should still be "random enough" anyway.
32 */
33 #define Perl_get_seed 0L
34 #endif /* Perl_seed */
35  
36 MODULE = Math::Random PACKAGE = Math::Random
37  
38 long
39 get_seed()
40 CODE:
41 3 ▶ RETVAL = Perl_get_seed;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = Perl_get_seed; 0 3 3
42 OUTPUT:
43 RETVAL
44  
45 double
46 genbet (aa,bb)
47 double aa
48 double bb
49  
50 double
51 genchi (df)
52 double df
53  
54 double
55 genexp (av)
56 double av
57  
58 double
59 genf (dfn,dfd)
60 double dfn
61 double dfd
62  
63 double
64 gengam (a,r)
65 double a
66 double r
67  
68 int
69 psetmn (p)
70 long p
71  
72 int
73 pgenmn ()
74 PROTOTYPE:
75  
76 int
77 rspriw (size)
78 long size
79  
80 int
81 rsprfw (size)
82 long size
83  
84 void
85 svprfw (index,value)
86 long index
87 double value
88  
89 void
90 pgnmul (n,ncat)
91 long n
92 long ncat
93  
94 long
95 gvpriw (index)
96 long index
97  
98 double
99 gennch (df,xnonc)
100 double df
101 double xnonc
102  
103 double
104 gennf (dfn,dfd,xnonc)
105 double dfn
106 double dfd
107 double xnonc
108  
109 double
110 gennor (av,sd)
111 double av
112 double sd
113  
114 void
115 pgnprm (n)
116 long n
117 PROTOTYPE: $
118  
119 double
120 genunf (low,high)
121 double low
122 double high
123  
124 long
125 ignpoi (mu)
126 double mu
127  
128 long
129 ignuin (low,high)
130 long low
131 long high
132  
133 long
134 ignnbn (n,p)
135 long n
136 double p
137  
138 long
139 ignbin (n,pp)
140 long n
141 double pp
142  
143 void
144 phrtsd (phrase)
145 char * phrase
146 PROTOTYPE: $
147 PREINIT:
148 long newseed1;
149 long newseed2;
150 PPCODE:
151 0 phrtsd(phrase,&newseed1,&newseed2);
152 0 ▶ EXTEND(sp, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp, 2); 0 0 0
153 0 PUSHs(sv_2mortal(newSViv(newseed1)));
154 0 PUSHs(sv_2mortal(newSViv(newseed2)));
155  
156 void
157 random_get_seed ()
158 PROTOTYPE:
159 PREINIT:
160 long newseed1;
161 long newseed2;
162 PPCODE:
163 10 getsd(&newseed1,&newseed2);
164 10 ▶ EXTEND(sp, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp, 2); 0 10 10
165 10 PUSHs(sv_2mortal(newSViv(newseed1)));
166 10 PUSHs(sv_2mortal(newSViv(newseed2)));
167  
168 void
169 salfph (phrase)
170 char * phrase
171 PROTOTYPE: $
172  
173 void
174 setall (iseed1,iseed2)
175 long iseed1
176 long iseed2
177 PROTOTYPE: $$
178  
179  
180 void
181 random_advance_state (k)
182 long k
183 CODE:
184 2 ▶ if ( k < 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ( k < 0 ) 0 2 2
185 0 croak("incorrect value for k; must be >=0");
186 2 advnst(k);
187  
188 void
189 random_init_generator (isdtyp)
190 long isdtyp
191 CODE:
192 4 ▶ if ( isdtyp != -1 && isdtyp != 0 && isdtyp != 1)
Branch: 3 branches
BranchTrueFalseTotal
if ( isdtyp != -1 && isdtyp != 0 && isdtyp != 1) 3 1 4
if ( isdtyp != -1 && isdtyp != 0 && isdtyp != 1) 2 1 3
if ( isdtyp != -1 && isdtyp != 0 && isdtyp != 1) 0 2 2
193 0 croak("incorrect value for isdtyp; must be -1, 0, or 1");
194 4 initgn(isdtyp);
195  
196 void
197 random_set_antithetic (qvalue)
198 long qvalue
199 CODE:
200 2 setant(qvalue);
201  
202 long
203 random_get_generator_num ()
204 PREINIT:
205 long old_g;
206 CODE:
207 2 gscgn(0, &old_g);
208 2 ▶ RETVAL = old_g;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = old_g; 0 2 2
209 OUTPUT:
210 RETVAL
211  
212 long
213 random_set_generator_num ( g)
214 long g
215 PREINIT:
216 long old_g;
217 CODE:
218 1 ▶ if ( g < 1 || g > 32 )
Branch: 2 branches
BranchTrueFalseTotal
if ( g < 1 || g > 32 ) 1 0 1
if ( g < 1 || g > 32 ) 0 1 1
219 0 croak("incorrect value for 'g'; must be 1 <= g <= 32");
220 1 gscgn(0, &old_g);
221 1 RETVAL = old_g;
222 1 gscgn(1, &g);
223 OUTPUT:
224 RETVAL
225  
226 long
227 random_integer ()
228 CODE:
229 209 RETVAL = ignlgi();
230 OUTPUT:
231 RETVAL
232  
233 double
234 gvprfw (index)
235 long index
236  
« randlib.c ↑ Summary helper.c »