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

Collection of methods to handle setting the various LR_obj parameters. More...

#include <stdarg.h>
#include <string.h>
#include "libran.h"
Include dependency graph for LRset.c:

Go to the source code of this file.

Functions

int LR_vset (LR_obj *o, char *x, va_list ap)
 LR_vset(LR_obj *o, char *x, va_list ap) - read and parse options. More...
 
int LR_set (LR_obj *o, char x,...)
 LR_set(LR_obj *o, char x, ...) - set a single LR object parameter. More...
 
int LR_set_all (LR_obj *o, char *x,...)
 LR_set_all(LR_obj *o, char *x, ...) - set all given LR object parameters. More...
 

Detailed Description

Collection of methods to handle setting the various LR_obj parameters.

The LR_obj contains many attributes for the various random variate distributions. These routines provide a simple interface for accomplishing initializing these attributes.

Here is an example of setting the end points for the uniformly distributed pseudo-random number generator.

#include "libran.h"
...
LR_obj *o = LR_new(unif, LR_double);
// set the end points
if (LR_set_all(o, "ab", 2.0, 5.0) > 0) {
// a serious error
LRperror("MyApp", o->errno);
...
}
// set the seed
LR_lsetseed(19580512L);
...
// generate random number between 2.0 and 5.0
x = LR_RAN(o);
...
// remove object
LR_rm(&o);
...

Definition in file LRset.c.

Function Documentation

◆ LR_set()

int LR_set ( LR_obj o,
char  x,
  ... 
)

LR_set(LR_obj *o, char x, ...) - set a single LR object parameter.

This routine is designed to set a single LR_obj attribute as directed by the format character. See LR_vset() for allowed list of format characters.

Parameters
oLR_obj object
xsingle character format
...optional argument
Returns
negative number of non-valid value in format string or error if > 0

Definition at line 165 of file LRset.c.

◆ LR_set_all()

int LR_set_all ( LR_obj o,
char *  x,
  ... 
)

LR_set_all(LR_obj *o, char *x, ...) - set all given LR object parameters.

Set a collection of LR_obj attributes. This routine has any number of arguments as defined by the format string (similar to printf() ).

See LR_vset() for list of allowed format string characters.

Parameters
oLR_obj object
xformat string
...optional arguments
Returns
negative number of non-valid values in format string or error if > 0

Definition at line 194 of file LRset.c.

◆ LR_vset()

int LR_vset ( LR_obj o,
char *  x,
va_list  ap 
)

LR_vset(LR_obj *o, char *x, va_list ap) - read and parse options.

This function is similar to vprintf() where the optional arguments are scanned according to format *x. The function accesses additional arguments by using the context information designated by ap. The program must execute va_start() before calling this function, and call va_end() afterward.

Generally there is no need to call this routine. Call LR_set_all() instead.

However, the list of attributes handled is important - 'k','n', 'p', 'q', 'd', 'a', 'b', 'm', 's', and 'x'. Any other characters are ignored except causing a negative value to be returned representing the number of such ignored characters. A real error will result in a positive return value.

All other characters in the format string are an ignorable error.

The precision of the input values are governed by the LR_obj LR_data_type, except for 'k','n' which are int only, and except for 'p','q' which are float only.

Parameters
oLR_obj object
xcontrolling format string
apadditional arguments context information
Returns
0 if no error else < 0 for non-valid characters in format string or an error if > 0

Definition at line 75 of file LRset.c.