LibRan  0.1
Pseudo-random number distribution generator
LRnew.c
Go to the documentation of this file.
1 
36 /*
37  * Copyright 2019 R.K. Owen, Ph.D.
38  * License see lgpl.md (Gnu Lesser General Public License)
39  */
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 #include <stdio.h>
45 #include <stdarg.h>
46 #include <stdlib.h> /* calloc,free */
47 #include <string.h> /* memcpy */
48 #include <math.h> /* NAN */
49 #include "libran.h"
50 #include "urand/urand.h"
51 
61  LR_obj *ptr = (void *) NULL;
62  if (!(ptr = (LR_obj *) calloc(sizeof(LR_obj),1)))
63  return ptr;
64  ptr->errno = 0;
65  ptr->d = d;
66  ptr->aux = (void *) NULL;
67  /* set all the pseudo-uniform random number generators */
68  ptr->ui = LR_irand;
69  ptr->ul = LR_lrand;
70  ptr->uf = LR_frand;
71  ptr->ud = LR_drand;
72 
73  /* set the default values based on LR_type */
74  ptr->t = t;
75  switch (t) {
76  case unif:
77  ptr->type = "unif";
78  if (d == LR_double) {
79  ptr->a.d = (double) 0.0;
80  ptr->b.d = (double) 1.0;
81  ptr->rnd = LRd_unif_RAN;
82  ptr->pdfd = LRd_unif_PDF;
83  ptr->cdfd = LRd_unif_CDF;
84  } else if (d == LR_float) {
85  ptr->a.f = (float) 0.0;
86  ptr->b.f = (float) 1.0;
87  ptr->rnf = LRf_unif_RAN;
88  ptr->pdff = LRf_unif_PDF;
89  ptr->cdff = LRf_unif_CDF;
90  } else {
91  /* error */
92  ptr->errno = LRerr_BadDataType;
93  }
94  break;
95  case piece:
96  {
97  ptr->type = "piece";
98  if (!(ptr->aux = (void *) calloc(sizeof(LR_pcs),1)))
99  goto objerr;
100  LR_pcs *aux = (LR_pcs *) ptr->aux;
101  aux->new = LR_pcs_new;
102  aux->rm = LR_pcs_rm;
103  aux->set = LR_pcs_set;
104  aux->normalize = LR_pcs_norm;
105  if (d == LR_double) {
106  ptr->a.d = (double) -1.0;
107  ptr->b.d = (double) 1.0;
108  ptr->x.d = (double) 1.0;
109  ptr->rnd = LRd_piece_RAN;
110  ptr->pdfd = LRd_piece_PDF;
111  ptr->cdfd = LRd_piece_CDF;
112  } else if (d == LR_float) {
113  ptr->a.f = (float) -1.0;
114  ptr->b.f = (float) 1.0;
115  ptr->x.f = (float) 1.0;
116  ptr->rnf = LRf_piece_RAN;
117  ptr->pdff = LRf_piece_PDF;
118  ptr->cdff = LRf_piece_CDF;
119  } else {
120  /* error */
121  ptr->errno = LRerr_BadDataType;
122  }
123  }
124  break;
125  case lspline:
126  {
127  ptr->type = "lspline";
128  if (!(ptr->aux = (void *) calloc(sizeof(LR_pcs),1)))
129  goto objerr;
130  LR_pcs *aux = (LR_pcs *) ptr->aux;
131  aux->new = LR_lspl_new;
132  aux->rm = LR_lspl_rm;
133  aux->set = LR_lspl_set;
134  aux->normalize = LR_lspl_norm;
135  if (d == LR_double) {
136  ptr->a.d = (double) -1.0;
137  ptr->b.d = (double) 1.0;
138  ptr->rnd = LRd_lspline_RAN;
139  ptr->pdfd = LRd_lspline_PDF;
140  ptr->cdfd = LRd_lspline_CDF;
141  } else if (d == LR_float) {
142  ptr->a.f = (float) -1.0;
143  ptr->b.f = (float) 1.0;
144  ptr->rnf = LRf_lspline_RAN;
145  ptr->pdff = LRf_lspline_PDF;
146  ptr->cdff = LRf_lspline_CDF;
147  } else {
148  /* error */
149  ptr->errno = LRerr_BadDataType;
150  }
151  }
152  break;
153  case uinvcdf:
154  {
155  ptr->type = "uinvcdf";
156  if (!(ptr->aux = (void *) calloc(sizeof(LR_uinvcdf),1)))
157  goto objerr;
158  LR_uinvcdf *aux = (LR_uinvcdf *) ptr->aux;
159  if (d == LR_double) {
160  aux->dcdf = NULL;
161  ptr->a.d = NAN;
162  ptr->b.d = NAN;
163  ptr->m.d = NAN;
164  ptr->s.d = NAN;
165  ptr->rnd = LRd_uinvcdf_RAN;
166  ptr->pdfd = LRd_uinvcdf_PDF;
167  ptr->cdfd = LRd_uinvcdf_CDF;
168  } else if (d == LR_float) {
169  aux->fcdf = NULL;
170  ptr->a.f = NAN;
171  ptr->b.f = NAN;
172  ptr->m.f = NAN;
173  ptr->s.f = NAN;
174  ptr->rnf = LRf_uinvcdf_RAN;
175  ptr->pdff = LRf_uinvcdf_PDF;
176  ptr->cdff = LRf_uinvcdf_CDF;
177  } else {
178  /* error */
179  ptr->errno = LRerr_BadDataType;
180  }
181  }
182  break;
183  case nexp:
184  ptr->type = "nexp";
185  if (d == LR_double) {
186  ptr->m.d = (double) 1.0;
187  ptr->s.d = NAN;
188  ptr->rnd = LRd_nexp_RAN;
189  ptr->pdfd = LRd_nexp_PDF;
190  ptr->cdfd = LRd_nexp_CDF;
191  } else if (d == LR_float) {
192  ptr->m.f = (float) 1.0;
193  ptr->s.f = NAN;
194  ptr->rnf = LRf_nexp_RAN;
195  ptr->pdff = LRf_nexp_PDF;
196  ptr->cdff = LRf_nexp_CDF;
197  } else {
198  /* error */
199  ptr->errno = LRerr_BadDataType;
200  }
201  break;
202  case erlang:
203  ptr->type = "erlang";
204  ptr->k = 1;
205  if (d == LR_double) {
206  ptr->m.d = (double) 1.0;
207  ptr->s.d = NAN;
208  ptr->rnd = LRd_erlang_RAN;
209  ptr->pdfd = LRd_erlang_PDF;
210  ptr->cdfd = LRd_erlang_CDF;
211  } else if (d == LR_float) {
212  ptr->m.f = (float) 1.0;
213  ptr->s.f = NAN;
214  ptr->rnf = LRf_erlang_RAN;
215  ptr->pdff = LRf_erlang_PDF;
216  ptr->cdff = LRf_erlang_CDF;
217  } else {
218  /* error */
219  ptr->errno = LRerr_BadDataType;
220  }
221  break;
222  case gausbm:
223  ptr->type = "gausbm";
224  if (d == LR_double) {
225  ptr->m.d = (double) 0.0;
226  ptr->s.d = (double) 1.0;
227  ptr->x.d = NAN;
228  ptr->rnd = LRd_gausbm_RAN;
229  ptr->pdfd = LRd_gaus_PDF;
230  ptr->cdfd = LRd_gaus_CDF;
231  } else if (d == LR_float) {
232  ptr->m.f = (float) 0.0;
233  ptr->s.f = (float) 1.0;
234  ptr->x.f = NAN;
235  ptr->rnf = LRf_gausbm_RAN;
236  ptr->pdff = LRf_gaus_PDF;
237  ptr->cdff = LRf_gaus_CDF;
238  } else {
239  /* error */
240  ptr->errno = LRerr_BadDataType;
241  }
242  break;
243  case gausmar:
244  ptr->type = "gausmar";
245  if (d == LR_double) {
246  ptr->m.d = (double) 0.0;
247  ptr->s.d = (double) 1.0;
248  ptr->x.d = NAN;
249  ptr->rnd = LRd_gausmar_RAN;
250  ptr->pdfd = LRd_gaus_PDF;
251  ptr->cdfd = LRd_gaus_CDF;
252  } else if (d == LR_float) {
253  ptr->m.f = (float) 0.0;
254  ptr->s.f = (float) 1.0;
255  ptr->x.f = NAN;
256  ptr->rnf = LRf_gausmar_RAN;
257  ptr->pdff = LRf_gaus_PDF;
258  ptr->cdff = LRf_gaus_CDF;
259  } else {
260  /* error */
261  ptr->errno = LRerr_BadDataType;
262  }
263  break;
264  case gsn2:
265  ptr->type = "gsn2";
266  if (d == LR_double) {
267  ptr->a.d = (double) -1.0;
268  ptr->b.d = (double) 1.0;
269  ptr->m.d = (double) 0.0;
270  ptr->s.d = (double) 1.0;
271  ptr->rnd = LRd_gsn2_RAN;
272  ptr->pdfd = LRd_gsn2_PDF;
273  ptr->cdfd = LRd_gsn2_CDF;
274  } else if (d == LR_float) {
275  ptr->a.f = (float) -1.0;
276  ptr->b.f = (float) 1.0;
277  ptr->m.f = (float) 0.0;
278  ptr->s.f = (float) 1.0;
279  ptr->rnf = LRf_gsn2_RAN;
280  ptr->pdff = LRf_gsn2_PDF;
281  ptr->cdff = LRf_gsn2_CDF;
282  } else {
283  /* error */
284  ptr->errno = LRerr_BadDataType;
285  }
286  break;
287  case gsn4:
288  ptr->type = "gsn4";
289  if (d == LR_double) {
290  ptr->a.d = (double) -2.0;
291  ptr->b.d = (double) 2.0;
292  ptr->m.d = (double) 0.0;
293  ptr->s.d = (double) 2.0;
294  ptr->rnd = LRd_gsn4_RAN;
295  ptr->pdfd = LRd_gsn4_PDF;
296  ptr->cdfd = LRd_gsn4_CDF;
297  } else if (d == LR_float) {
298  ptr->a.f = (float) -2.0;
299  ptr->b.f = (float) 2.0;
300  ptr->m.f = (float) 0.0;
301  ptr->s.f = (float) 2.0;
302  ptr->rnf = LRf_gsn4_RAN;
303  ptr->pdff = LRf_gsn4_PDF;
304  ptr->cdff = LRf_gsn4_CDF;
305  } else {
306  /* error */
307  ptr->errno = LRerr_BadDataType;
308  }
309  break;
310  case gsn12:
311  ptr->type = "gsn12";
312  if (d == LR_double) {
313  ptr->a.d = (double) -6.0;
314  ptr->b.d = (double) 6.0;
315  ptr->m.d = (double) 0.0;
316  ptr->s.d = (double) 1.0;
317  ptr->rnd = LRd_gsn12_RAN;
318  ptr->pdfd = LRd_gsn12_PDF;
319  ptr->cdfd = LRd_gsn12_CDF;
320  } else if (d == LR_float) {
321  ptr->a.f = (float) -6.0;
322  ptr->b.f = (float) 6.0;
323  ptr->m.f = (float) 0.0;
324  ptr->s.f = (float) 1.0;
325  ptr->rnf = LRf_gsn12_RAN;
326  ptr->pdff = LRf_gsn12_PDF;
327  ptr->cdff = LRf_gsn12_CDF;
328  } else {
329  /* error */
330  ptr->errno = LRerr_BadDataType;
331  }
332  break;
333  case cauchy:
334  ptr->type = "cauchy";
335  if (d == LR_double) {
336  ptr->m.d = (double) 0.0;
337  ptr->s.d = (double) 1.0;
338  ptr->rnd = LRd_cauchy_RAN;
339  ptr->pdfd = LRd_cauchy_PDF;
340  ptr->cdfd = LRd_cauchy_CDF;
341  } else if (d == LR_float) {
342  ptr->m.f = (float) 0.0;
343  ptr->s.f = (float) 1.0;
344  ptr->rnf = LRf_cauchy_RAN;
345  ptr->pdff = LRf_cauchy_PDF;
346  ptr->cdff = LRf_cauchy_CDF;
347  } else {
348  /* error */
349  ptr->errno = LRerr_BadDataType;
350  }
351  break;
352  case cauchymar:
353  ptr->type = "cauchymar";
354  if (d == LR_double) {
355  ptr->m.d = (double) 0.0;
356  ptr->s.d = (double) 1.0;
357  ptr->rnd = LRd_cauchymar_RAN;
358  ptr->pdfd = LRd_cauchy_PDF;
359  ptr->cdfd = LRd_cauchy_CDF;
360  } else if (d == LR_float) {
361  ptr->m.f = (float) 0.0;
362  ptr->s.f = (float) 1.0;
363  ptr->rnf = LRf_cauchymar_RAN;
364  ptr->pdff = LRf_cauchy_PDF;
365  ptr->cdff = LRf_cauchy_CDF;
366  } else {
367  /* error */
368  ptr->errno = LRerr_BadDataType;
369  }
370  break;
371  case poisson:
372  ptr->type = "poisson";
373  if (d == LR_int) {
374  ptr->p = (float) 1.0;
375  ptr->q = NAN;
376  ptr->rni = LRi_poisson_RAN;
377  ptr->pdfi = LRi_poisson_PDF;
378  ptr->cdfi = LRi_poisson_CDF;
379  } else {
380  /* error */
381  ptr->errno = LRerr_BadDataType;
382  }
383  break;
384  case geometric:
385  ptr->type = "geometric";
386  if (d == LR_int) {
387  ptr->p = (float) 0.5;
388  ptr->q = NAN;
389  ptr->rni = LRi_geometric_RAN;
390  ptr->pdfi = LRi_geometric_PDF;
391  ptr->cdfi = LRi_geometric_CDF;
392  } else {
393  /* error */
394  ptr->errno = LRerr_BadDataType;
395  }
396  break;
397  case binomial:
398  ptr->type = "binomial";
399  if (d == LR_int) {
400  ptr->p = (float) 0.5;
401  ptr->q = NAN;
402  ptr->n = 0;
403  ptr->rni = LRi_binomial_RAN;
404  ptr->pdfi = LRi_binomial_PDF;
405  ptr->cdfi = LRi_binomial_CDF;
406  } else {
407  /* error */
408  ptr->errno = LRerr_BadDataType;
409  }
410  break;
411  default:
412  /* error */
413  ptr->errno = LRerr_BadLRType;
414  break;
415  }
416 
417  return ptr;
418 
419 objerr:
420  free((void *) ptr);
421  ptr = (void *) NULL;
422  return ptr;
423 }
424 
432 int LR_rm(LR_obj **o) {
433  /* check if LR_obj */
434  if (o && *o) {
435  if (((*o)->t == piece)
436  || ((*o)->t == lspline)) {
437  free((void *) (*o)->aux);
438  }
439  switch ((*o)->d) {
440  case LR_int:
441  case LR_long:
442  case LR_float:
443  case LR_double:
444  free((void *) *o);
445  *o = (LR_obj *) NULL;
446  return LRerr_OK;
447  default:
448  return LRerr_BadDataType;
449  }
450  }
451 }
452 
470 int LR_check(LR_obj *o) {
471  double td, dzero = 0.0;
472  float tf, fzero = 0.0;
473  /* check if LR_obj */
474  if (o && o->t && o->d) {
475  switch (o->t) {
476  /* interval types (a,b) */
477  case unif:
478  case piece:
479  case lspline:
480  case gsn2:
481  case gsn4:
482  if (o->d == LR_double) {
483  if (o->a.d > o->b.d) {
484  td = o->a.d;
485  o->a.d = o->b.d;
486  o->b.d = td;
487  } else if (o->a.d == o->b.d) {
488  return o->errno = LRerr_InvalidRange;
489  }
490  } else if (o->d == LR_float) {
491  if (o->a.f > o->b.f) {
492  tf = o->a.f;
493  o->a.f = o->b.f;
494  o->b.f = tf;
495  } else if (o->a.d == o->b.d) {
496  return o->errno = LRerr_InvalidRange;
497  }
498  } else {
499  /* error */
500  return o->errno = LRerr_BadDataType;
501  }
502  return LRerr_OK;
503 
504  /* mixed attributes (a,b,m,s) */
505  case uinvcdf:
506  if (o->d == LR_double) {
507  if ((!isnan(o->a.d)) && (!isnan(o->b.d))) {
508  if (o->a.d > o->b.d) {
509  td = o->a.d;
510  o->a.d = o->b.d;
511  o->b.d = td;
512  } else if (o->a.d == o->b.d) {
513  return o->errno = LRerr_InvalidRange;
514  }
515  }
516  if ((!isnan(o->s.d))) {
517  if (o->s.d < dzero) {
518  o->s.d = - o->s.d;
519  } else if (o->s.d == dzero) {
520  return o->errno
522  }
523  }
524  if (isnan(o->a.d) && isnan(o->b.d)
525  && isnan(o->m.d) && isnan(o->s.d))
526  return o->errno = LRerr_UnmetPreconditions;
527 
528  } else if (o->d == LR_float) {
529  if ((!isnan(o->a.f)) && (!isnan(o->b.f))) {
530  if (o->a.f > o->b.f) {
531  tf = o->a.f;
532  o->a.f = o->b.f;
533  o->b.f = tf;
534  } else if (o->a.f == o->b.f) {
535  return o->errno = LRerr_InvalidRange;
536  }
537  }
538  if ((!isnan(o->s.f))) {
539  if (o->s.f < fzero) {
540  o->s.f = - o->s.f;
541  } else if (o->s.f == fzero) {
542  return o->errno
544  }
545  }
546  if (isnan(o->a.f) && isnan(o->b.f)
547  && isnan(o->m.f) && isnan(o->s.f))
548  return o->errno = LRerr_UnmetPreconditions;
549 
550  } else {
551  /* error */
552  return o->errno = LRerr_BadDataType;
553  }
554  return LRerr_OK;
555 
556  /* full range (m,s) */
557  case gausbm:
558  case gausmar:
559  case gsn12:
560  case cauchy:
561  case cauchymar:
562  if (o->d == LR_double) {
563  if (o->s.d < dzero) {
564  o->s.d = - o->s.d;
565  } else if (o->s.d == dzero) {
566  return o->errno
568  }
569  } else if (o->d == LR_float) {
570  if (o->s.f < fzero) {
571  o->s.f = - o->s.f;
572  } else if (o->s.f == fzero) {
573  return o->errno
575  }
576  } else {
577  /* error */
578  return o->errno = LRerr_BadDataType;
579  }
580  return LRerr_OK;
581  /* semi-infinite (m)*/
582  case nexp:
583  if (o->d == LR_double) {
584  if (o->m.d < dzero) {
585  o->m.d = - o->m.d;
586  } else if (o->m.d == dzero) {
587  return o->errno
589  }
590  } else if (o->d == LR_float) {
591  if (o->m.f < fzero) {
592  o->m.f = - o->m.f;
593  } else if (o->m.f == fzero) {
594  return o->errno
596  }
597  } else {
598  /* error */
599  return o->errno = LRerr_BadDataType;
600  }
601  return LRerr_OK;
602 
603  case erlang:
604  if (o->k < 0) {
605  o->k = - o->k;
606  } else if (o->k == 0) {
607  return o->errno = LRerr_InvalidInputValue;
608  }
609  if (o->d == LR_double) {
610  if (o->m.d < dzero) {
611  o->m.d = - o->m.d;
612  } else if (o->m.d == dzero) {
613  return o->errno
615  }
616  } else if (o->d == LR_float) {
617  if (o->m.f < fzero) {
618  o->m.f = - o->m.f;
619  } else if (o->m.f == fzero) {
620  return o->errno
622  }
623  } else {
624  /* error */
625  return o->errno = LRerr_BadDataType;
626  }
627  return LRerr_OK;
628 
629  case poisson:
630  if (o->p < 0) {
631  o->p = - o->p;
632  } else if (o->p == 0) {
633  return o->errno = LRerr_InvalidInputValue;
634  }
635  return LRerr_OK;
636 
637  case geometric:
638  if (o->p < 0) {
639  o->p = - o->p;
640  }
641  if (o->p == 0 || o->p > 1) {
642  return o->errno = LRerr_InvalidInputValue;
643  }
644  return LRerr_OK;
645 
646  case binomial:
647  if (o->p < 0) {
648  o->p = - o->p;
649  }
650  if (o->n < 0) {
651  o->n = - o->n;
652  }
653  if (o->n < 1 || o->p == 0 || o->p > 1) {
654  return o->errno = LRerr_InvalidInputValue;
655  }
656  return LRerr_OK;
657 
658  default:
659  return o->errno = LRerr_BadLRType;
660  }
661  } else {
662  return LRerr_Unspecified;
663  }
664 }
665 
666 #ifdef __cplusplus
667 }
668 #endif
float LRf_gsn4_CDF(LR_obj *o, float x)
LRf_gsn4_CDF(LR_obj *o, float x) - float gaussian-like (saw tooth) cumulative distribution function...
Definition: LRgsn.c:496
LR_data_type
an enum of allowed value types
Definition: libran.h:98
double LRd_nexp_RAN(LR_obj *o)
LRd_nexp_RAN(LR_obj *o) - double random negative exponential distribution using the inversion method...
Definition: LRnexp.c:57
double LRd_unif_RAN(LR_obj *o)
LRd_unif_RAN(LR_obj *o) - double random uniform distribution.
Definition: LRunif.c:55
LR_val b
Definition: libran.h:139
#define LRerr_OK
Definition: libran.h:32
float(* cdff)(LR_obj *, float)
Definition: libran.h:164
LR_data_type d
Definition: libran.h:137
double LRd_unif_PDF(LR_obj *o, double x)
LRd_unif_PDF(LR_obj *o, double x) - double uniform probablity distribution function.
Definition: LRunif.c:69
double LRd_nexp_PDF(LR_obj *o, double x)
LRd_nexp_PDF(LR_obj *o, double x) - double negative exponential probablity distribution function...
Definition: LRnexp.c:75
float(* pdff)(LR_obj *, float)
Definition: libran.h:160
float LRf_cauchymar_RAN(LR_obj *o)
LRf_cauchymar_RAN(LR_obj *o) - float random Cauchy/Lorentz distribution using the polar method and th...
Definition: LRcauchy.c:147
double LR_drand(LR_obj *)
LR_drand(LR_obj *) - returns double in range [0.0,1.0)
Definition: urand.c:342
Definition: libran.h:59
float LRf_lspline_CDF(LR_obj *o, float x)
LRf_lspline_CDF(LR_obj *o, float x) - float linear spline cumulative distribution function...
Definition: LRlspline.c:390
float LRi_poisson_CDF(LR_obj *o, int x)
LRi_poisson_CDF(LR_obj *o, int x) - Poisson distribution cumulative distribution function.
Definition: LRpoisson.c:116
double LRd_gsn4_CDF(LR_obj *o, double x)
LRd_gsn4_CDF(LR_obj *o, double x) - double gaussian-like (saw tooth) cumulative distribution function...
Definition: LRgsn.c:418
void * aux
Definition: libran.h:168
int LR_rm(LR_obj **o)
LR_rm(LR_obj **o) - destroy the LR object and release allocated memory.
Definition: LRnew.c:432
float LRf_erlang_PDF(LR_obj *o, float x)
LRf_erlang_PDF(LR_obj *o, float x) - Erlang distribution probablity distribution function.
Definition: LRerlang.c:163
double LRd_piece_PDF(LR_obj *o, double x)
LRd_piece_PDF(LR_obj *o, double x) - double piecewise uniform probablity distribution function...
Definition: LRpiece.c:305
double LRd_erlang_CDF(LR_obj *o, double x)
LRd_erlang_CDF(LR_obj *o, double x) - Erlang distribution cumulative distribution function...
Definition: LRerlang.c:118
float LRf_gsn2_CDF(LR_obj *o, float x)
LRf_gsn2_CDF(LR_obj *o, float x) - float gaussian-like (saw tooth) cumulative distribution function...
Definition: LRgsn.c:271
Definition: libran.h:60
int LR_pcs_norm(LR_obj *o)
LR_pcs_norm(LR_obj *o) - normalize the interval scale factors.
Definition: LRpiece.c:220
int LRi_binomial_RAN(LR_obj *o)
LRi_binomial_RAN(LR_obj *o) - int Binomial distributed variate. Default values: probability of succes...
Definition: LRbinom.c:82
int LR_check(LR_obj *o)
LR_check(LR_obj *o) - check and fix the LR object parameters if possible.
Definition: LRnew.c:470
double LRd_gsn4_RAN(LR_obj *o)
LRd_gsn4_RAN(LR_obj *o) - double random g4 gaussian-like (simple bell curve) distribution.
Definition: LRgsn.c:373
float LRf_piece_RAN(LR_obj *o)
LRf_piece_RAN(LR_obj *o) - float random piecewise uniform distribution.
Definition: LRpiece.c:360
LR_type
an enum of allowed random variate distribution types
Definition: libran.h:52
int LRi_poisson_RAN(LR_obj *o)
LRi_poisson_RAN(LR_obj *o) - int Poisson distributed variate. Default values: scale m = 1...
Definition: LRpoisson.c:66
int LR_irand(LR_obj *)
LR_irand(LR_obj *) - returns int in range [0,LR_IRAND_IMAX].
Definition: urand.c:121
float p
Definition: libran.h:145
double(* rnd)(LR_obj *)
Definition: libran.h:157
LR_obj * LR_new(LR_type t, LR_data_type d)
LR_new(LR_type t, LR_data_type d) - create the LR object and preset some default parameter values...
Definition: LRnew.c:60
LR_val x
Definition: libran.h:142
float LRf_gausmar_RAN(LR_obj *o)
LRf_gausmar_RAN(LR_obj *o) - float random Gaussian/Normal distribution using the Marsaglia method wit...
Definition: LRgaus.c:193
int LR_pcs_set(LR_obj *o, double x, double p)
LR_pcs_set(LR_obj *o, double x) - add interval boundary (will order internally).
Definition: LRpiece.c:158
float LRf_cauchy_CDF(LR_obj *o, float x)
LRf_cauchy_CDF(LR_obj *o, float x) - float Cauchy/Lorentz cumulative distribution function...
Definition: LRcauchy.c:180
#define LRerr_UnmetPreconditions
Definition: libran.h:43
float LRf_lspline_PDF(LR_obj *o, float x)
LRf_lspline_PDF(LR_obj *o, float x) - float linear spline probablity distribution function...
Definition: LRlspline.c:356
A special object for defining some of the random variate distributions.
Definition: libran.h:206
Definition: libran.h:70
Definition: libran.h:65
const char const * type
Definition: libran.h:135
double LRd_lspline_CDF(LR_obj *o, double x)
LRd_lspline_CDF(LR_obj *o, double x) - double linear spline cumulative distribution function...
Definition: LRlspline.c:281
long(* ul)(LR_obj *)
Definition: libran.h:152
Definition: libran.h:66
float LRf_nexp_CDF(LR_obj *o, float x)
LRf_nexp_CDF(LR_obj *o, float x) - float negative exponential cumulative distribution function...
Definition: LRnexp.c:148
float LRf_unif_CDF(LR_obj *o, float x)
LRf_unif_CDF(LR_obj *o, float x) - float uniform cumulative distribution function.
Definition: LRunif.c:135
double LRd_gausbm_RAN(LR_obj *o)
LRd_gausbm_RAN(LR_obj *o) - double random Gaussian/Normal distribution using the Box-Muller method...
Definition: LRgaus.c:72
float LRf_unif_RAN(LR_obj *o)
LRf_unif_RAN(LR_obj *o) - float random uniform distribution.
Definition: LRunif.c:104
#define LRerr_InvalidRange
Definition: libran.h:42
Definition: libran.h:62
long LR_lrand(LR_obj *)
LR_lrand(LR_obj *) - returns long in range [0,LR_IRAND_LMAX].
Definition: urand.c:270
double LRd_gsn12_PDF(LR_obj *o, double x)
LRd_gsn12_PDF(LR_obj *o, double x) - double gaussian-like (simple bell curve) probablity distribution...
Definition: LRgsn.c:659
Definition: libran.h:54
float LRi_geometric_PDF(LR_obj *o, int x)
LRi_geometric_PDF(LR_obj *o, int x) - Geometric probablity (or mass) distribution function...
Definition: LRgeom.c:88
Definition: libran.h:64
double LRd_gsn2_CDF(LR_obj *o, double x)
LRd_gsn2_CDF(LR_obj *o, double x) - double gaussian-like (saw tooth) cumulative distribution function...
Definition: LRgsn.c:206
Definition: libran.h:58
int(* set)(LR_obj *o, double x, double p)
Definition: libran.h:218
double LRd_gsn12_CDF(LR_obj *o, double x)
LRd_gsn12_CDF(LR_obj *o, double x) - double gaussian-like (simple bell curve) cumulative distribution...
Definition: LRgsn.c:688
float LRf_gaus_PDF(LR_obj *o, float x)
LRf_gaus_PDF(LR_obj *o, float x) - float Gaussian/Normal probablity distribution function.
Definition: LRgaus.c:221
double(* cdfd)(LR_obj *, double)
Definition: libran.h:165
float LRf_gsn12_CDF(LR_obj *o, float x)
LRf_gsn12_CDF(LR_obj *o, float x) - float gaussian-like (simple bell curve) cumulative distribution f...
Definition: LRgsn.c:770
#define LRerr_BadDataType
Definition: libran.h:34
int LRi_geometric_RAN(LR_obj *o)
LRi_geometric_RAN(LR_obj *o) - int Geometric distributed variate. Default values: probability of succ...
Definition: LRgeom.c:68
float LRf_uinvcdf_CDF(LR_obj *o, float x)
LRf_uinvcdf_CDF(LR_obj *o, float x) - float User supplied cumulative distribution function...
Definition: LRuinvcdf.c:666
float LRf_gsn12_PDF(LR_obj *o, float x)
LRf_gsn12_PDF(LR_obj *o, float x) - float gaussian-like (simple bell curve) probablity distribution f...
Definition: LRgsn.c:741
float LRf_lspline_RAN(LR_obj *o)
LRf_lspline_RAN(LR_obj *o) - float random linear spline distribution.
Definition: LRlspline.c:318
float LRf_cauchy_PDF(LR_obj *o, float x)
LRf_cauchy_PDF(LR_obj *o, float x) - float Cauchy/Lorentz probablity distribution function...
Definition: LRcauchy.c:166
float LRf_gsn2_PDF(LR_obj *o, float x)
LRf_gsn2_PDF(LR_obj *o, float x) - float gaussian-like (saw tooth) probablity distribution function...
Definition: LRgsn.c:248
double(* ud)(LR_obj *)
Definition: libran.h:154
double LRd_cauchy_CDF(LR_obj *o, double x)
LRd_cauchy_CDF(LR_obj *o, double x) - double Cauchy/Lorentz cumulative distribution function...
Definition: LRcauchy.c:117
float LR_frand(LR_obj *)
LR_frand(LR_obj *) - returns float in range [0.0,1.0)
Definition: urand.c:193
float LRf_uinvcdf_PDF(LR_obj *o, float x)
LRf_uinvcdf_PDF(LR_obj *o, float x) - float probability distribution function approximated from the u...
Definition: LRuinvcdf.c:611
double LRd_gsn2_RAN(LR_obj *o)
LRd_gsn2_RAN(LR_obj *o) - double random g2 gaussian-like (saw tooth) distribution.
Definition: LRgsn.c:169
int LR_pcs_rm(LR_obj *o)
LR_pcs_rm(LR_obj *o) - strip out the LR_pcs object part of LR_obj.
Definition: LRpiece.c:122
double LRd_gsn4_PDF(LR_obj *o, double x)
LRd_gsn4_PDF(LR_obj *o, double x) - double gaussian-like (simple bell curve) probablity distribution ...
Definition: LRgsn.c:388
float LRf_gsn12_RAN(LR_obj *o)
LRf_gsn12_RAN(LR_obj *o) - float random g12 gaussian-like distribution closely matches a Gaussian/Nor...
Definition: LRgsn.c:721
double LRd_gsn12_RAN(LR_obj *o)
LRd_gsn12_RAN(LR_obj *o) - double random g12 gaussian-like distribution closely matches a Gaussian/No...
Definition: LRgsn.c:639
float LRf_gsn4_PDF(LR_obj *o, float x)
LRf_gsn4_PDF(LR_obj *o, float x) - float gaussian-like (simple bell curve) probablity distribution fu...
Definition: LRgsn.c:466
float LRf_erlang_CDF(LR_obj *o, float x)
LRf_erlang_CDF(LR_obj *o, float x) - Erlang distribution cumulative distribution function.
Definition: LRerlang.c:194
A special object for using a user defined CDF.
Definition: libran.h:238
float LRf_gaus_CDF(LR_obj *o, float x)
LRf_gaus_CDF(LR_obj *o, float x) - float Gaussian/Normal cumulative distribution function.
Definition: LRgaus.c:238
int(* normalize)(LR_obj *o)
Definition: libran.h:219
float LRf_gausbm_RAN(LR_obj *o)
LRf_gausbm_RAN(LR_obj *o) - float random Gaussian/Normal distribution using the Box-Muller method...
Definition: LRgaus.c:165
LR_type t
Definition: libran.h:136
float q
Definition: libran.h:146
double LRd_gsn2_PDF(LR_obj *o, double x)
LRd_gsn2_PDF(LR_obj *o, double x) - double gaussian-like (saw tooth) probablity distribution function...
Definition: LRgsn.c:183
Definition: libran.h:68
double LRd_piece_CDF(LR_obj *o, double x)
LRd_piece_CDF(LR_obj *o, double x) - double piecewise uniform cumulative distribution function...
Definition: LRpiece.c:332
double LRd_lspline_RAN(LR_obj *o)
LRd_lspline_RAN(LR_obj *o) - double random linear spline distribution random variate.
Definition: LRlspline.c:209
Definition: libran.h:69
double LRd_uinvcdf_RAN(LR_obj *o)
LRd_uinvcdf_RAN(LR_obj *o) - double random variate via inverse method of the UserCDF() fn...
Definition: LRuinvcdf.c:269
LR_val s
Definition: libran.h:141
double LRd_piece_RAN(LR_obj *o)
LRd_piece_RAN(LR_obj *o) - double random piecewise uniform distribution random variate.
Definition: LRpiece.c:277
double(* pdfd)(LR_obj *, double)
Definition: libran.h:161
int LR_lspl_new(LR_obj *o, int n)
LR_lspl_new(LR_obj *o, int n) - create a new linear spline object.
Definition: LRlspline.c:88
float LRi_binomial_PDF(LR_obj *o, int x)
LRi_binomial_PDF(LR_obj *o, int k) - Binomial probablity (or mass) distribution function.
Definition: LRbinom.c:108
float(* cdfi)(LR_obj *, int)
Definition: libran.h:166
int errno
Definition: libran.h:169
LR_val a
Definition: libran.h:138
int(* rni)(LR_obj *)
Definition: libran.h:158
#define LRerr_BadLRType
Definition: libran.h:35
double d
Definition: libran.h:87
double LRd_gaus_PDF(LR_obj *o, double x)
LRd_gaus_PDF(LR_obj *o, double x) - double Gaussian/Normal probablity distribution function...
Definition: LRgaus.c:129
double LRd_cauchymar_RAN(LR_obj *o)
LRd_cauchymar_RAN(LR_obj *o) - double random Cauchy/Lorentz distribution using the polar method and t...
Definition: LRcauchy.c:84
float f
Definition: libran.h:86
float LRf_uinvcdf_RAN(LR_obj *o)
LRf_uinvcdf_RAN(LR_obj *o) - float random variate via inverse method of the UserCDF() fn...
Definition: LRuinvcdf.c:551
float(* uf)(LR_obj *)
Definition: libran.h:153
Definition: libran.h:61
float LRf_unif_PDF(LR_obj *o, float x)
LRf_unif_PDF(LR_obj *o, float x) - float uniform probablity distribution function.
Definition: LRunif.c:118
int LR_lspl_rm(LR_obj *o)
LR_lspl_rm(LR_obj *o) - strip out the LR_lspl object part of LR_obj.
Definition: LRlspline.c:100
int k
Definition: libran.h:143
float LRf_piece_PDF(LR_obj *o, float x)
LRf_piece_PDF(LR_obj *o, float x) - float piecewise uniform probablity distribution function...
Definition: LRpiece.c:388
float LRi_geometric_CDF(LR_obj *o, int x)
LRi_geometric_CDF(LR_obj *o, int x) - Geometric distribution cumulative distribution function...
Definition: LRgeom.c:112
Definition: libran.h:63
float LRf_piece_CDF(LR_obj *o, float x)
LRf_piece_CDF(LR_obj *o, float x) - float piecewise uniform cumulative distribution function...
Definition: LRpiece.c:415
float(* rnf)(LR_obj *)
Definition: libran.h:156
double LRd_cauchy_PDF(LR_obj *o, double x)
LRd_cauchy_PDF(LR_obj *o, double x) - double Cauchy/Lorentz probablity distribution function...
Definition: LRcauchy.c:103
double LRd_erlang_PDF(LR_obj *o, double x)
LRd_erlang_PDF(LR_obj *o, double x) - Erlang distribution probablity distribution function...
Definition: LRerlang.c:87
int(* ui)(LR_obj *)
Definition: libran.h:151
double LRd_unif_CDF(LR_obj *o, double x)
LRd_unif_CDF(LR_obj *o, double x) - double uniform cumulative distribution function.
Definition: LRunif.c:86
int(* rm)(LR_obj *o)
Definition: libran.h:217
float LRf_nexp_PDF(LR_obj *o, float x)
LRf_nexp_PDF(LR_obj *o, float x) - float negative exponential probablity distribution function...
Definition: LRnexp.c:130
double LRd_cauchy_RAN(LR_obj *o)
LRd_cauchy_RAN(LR_obj *o) - double random Cauchy/Lorentz distribution using the inversion method on t...
Definition: LRcauchy.c:71
float LRf_nexp_RAN(LR_obj *o)
LRf_nexp_RAN(LR_obj *o) - float random negative exponential distribution using the inversion method...
Definition: LRnexp.c:112
The LibRan common header file.
#define LRerr_Unspecified
Definition: libran.h:33
int LR_lspl_set(LR_obj *o, double x, double p)
LR_lspl_set(LR_obj *o, double x) - add interval boundary (will order internally). ...
Definition: LRlspline.c:128
int n
Definition: libran.h:144
double LRd_uinvcdf_PDF(LR_obj *o, double x)
LRd_uinvcdf_PDF(LR_obj *o, double x) - double probability distribution function approximated from the...
Definition: LRuinvcdf.c:329
int LR_pcs_new(LR_obj *o, int n)
LR_pcs_new(LR_obj *o, int n) - create a new piecewise uniform object set of segments.
Definition: LRpiece.c:78
double LRd_gaus_CDF(LR_obj *o, double x)
LRd_gaus_CDF(LR_obj *o, double x) - double Gaussian/Normal cumulative distribution function...
Definition: LRgaus.c:146
#define LRerr_InvalidInputValue
Definition: libran.h:41
double LRd_gausmar_RAN(LR_obj *o)
LRd_gausmar_RAN(LR_obj *o) - double random Gaussian/Normal distribution using the Marsaglia method wi...
Definition: LRgaus.c:101
float LRf_erlang_RAN(LR_obj *o)
LRf_erlang_RAN(LR_obj *o) - float random negative exponential distribution using the inversion method...
Definition: LRerlang.c:142
float LRf_cauchy_RAN(LR_obj *o)
LRf_cauchy_RAN(LR_obj *o) - float random Cauchy/Lorentz distribution using the inversion method...
Definition: LRcauchy.c:134
the fundamental LibRan random variate distribution object
Definition: libran.h:134
float LRf_gsn4_RAN(LR_obj *o)
LRf_gsn4_RAN(LR_obj *o) - float random g4 gaussian-like (simple bell curve) distribution.
Definition: LRgsn.c:451
LR_val m
Definition: libran.h:140
double LRd_erlang_RAN(LR_obj *o)
LRd_erlang_RAN(LR_obj *o) - double random negative exponential distribution using the inversion metho...
Definition: LRerlang.c:66
double LRd_uinvcdf_CDF(LR_obj *o, double x)
LRd_uinvcdf_CDF(LR_obj *o, double x) - double User supplied cumulative distribution function...
Definition: LRuinvcdf.c:384
double LRd_lspline_PDF(LR_obj *o, double x)
LRd_lspline_PDF(LR_obj *o, double x) - double linear spline probablity distribution function...
Definition: LRlspline.c:247
float LRi_binomial_CDF(LR_obj *o, int x)
LRi_binomial_CDF(LR_obj *o, int k) - Binomial distribution cumulative distribution function...
Definition: LRbinom.c:133
int LR_lspl_norm(LR_obj *o)
LR_lspl_norm(LR_obj *o) - normalize the interval scale factors.
Definition: LRlspline.c:147
float LRi_poisson_PDF(LR_obj *o, int x)
LRi_poisson_PDF(LR_obj *o, int x) - Poisson probablity (or mass) distribution function.
Definition: LRpoisson.c:91
Definition: libran.h:99
float(* pdfi)(LR_obj *, int)
Definition: libran.h:162
double LRd_nexp_CDF(LR_obj *o, double x)
LRd_nexp_CDF(LR_obj *o, double x) - double negative exponential cumulative distribution function...
Definition: LRnexp.c:93
float LRf_gsn2_RAN(LR_obj *o)
LRf_gsn2_RAN(LR_obj *o) - float random g2 gaussian-like (saw tooth) distribution. ...
Definition: LRgsn.c:234
int(* new)(LR_obj *o, int n)
Definition: libran.h:216