LibRan  0.1
Pseudo-random number distribution generator
Functions
LRnew.c File Reference

Create a new LR_obj object and set some parameter values. More...

#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "libran.h"
#include "urand/urand.h"
Include dependency graph for LRnew.c:

Go to the source code of this file.

Functions

LR_objLR_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. More...
 
int LR_rm (LR_obj **o)
 LR_rm(LR_obj **o) - destroy the LR object and release allocated memory. More...
 
int LR_check (LR_obj *o)
 LR_check(LR_obj *o) - check and fix the LR object parameters if possible. More...
 

Detailed Description

Create a new LR_obj object and set some parameter values.

Use these methods to create the LR_obj object by allocating memory, and set certain of the parameters to default values dependent on the random variate type given. Other of the routines set these LR_obj object attributes or remove the object. Lastly there is a check method to correct any of the parameter values where possible. (E.g. the interval boundaries b > a, width s > 0, etc.)

The following code segment sets up a LR_obj object to generate uniform distributed random variates on the interval (a=1, b=3).

#include "libran.h"
...
LR_obj *o = LR_new(unif, LR_double);
// set the parameters from the default
LR_set_all(o, "ab", 1., 3.);
// check parameters
// set the seed
LR_lsetseed(19580512L);
...
// generate random number
x = LR_RAN(o);
...
// remove object
LR_rm(&o);
...

Definition in file LRnew.c.

Function Documentation

◆ LR_check()

int LR_check ( LR_obj o)

LR_check(LR_obj *o) - check and fix the LR object parameters if possible.

This method finds and addresses fixable errors. For example for those random variate distributions that use the interval end points (a,b) the check method will switch 'a' and 'b' if 'a' > 'b'. The other example is for those distributions that use 's' which generally relates to the width of the peak. This value should be positive and the check will take the absolute value of this value if negative.

However, non-fixable errors will raise an error, such as a=b in the first case or s=0 for the second case.

Parameters
oLR_obj pointer
Returns
0 if successful, non-zero if an error or not possible to fix

Definition at line 470 of file LRnew.c.

◆ LR_new()

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.

Parameters
tLR_type (e.g. LR_gausbm)
dLR_data_type (e.g. LR_double)
Returns
LR_obj *

Definition at line 60 of file LRnew.c.

◆ LR_rm()

int LR_rm ( LR_obj **  o)

LR_rm(LR_obj **o) - destroy the LR object and release allocated memory.

Parameters
oAddress of LR_obj pointer
Returns
0 if successful, non-zero if an error

Definition at line 432 of file LRnew.c.