21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

The egads_randlong( ) function gets a pseudo-random long value, whereas egads_<br />

randulong( ) gets a pseudo-random unsigned long value from 0 to ULONG_MAX inclusive.<br />

The functions egads_randint( ) and egads_randuint( ) do the same things, but<br />

on integer types instead of longs. To get a random integer in a specified range, use<br />

the function egads_randrange( ). The min and max arguments are both inclusive,<br />

meaning that they are both values that can possibly be returned.<br />

void egads_randreal(prngctx_t * ctx, double *out, int *error);<br />

void egads_randuniform(prngctx_t *ctx, double *out, double min, double max,<br />

int *error);<br />

void egads_gauss(prngctx_t *ctx, double *out, double mu, double sigma,<br />

int *error);<br />

void egads_normalvariate(prngctx_t *ctx, double *out, double mu, double sigma,<br />

int *error);<br />

void egads_lognormalvariate(prngctx_t *ctx, double *out, double mu, double sigma,<br />

int *error);<br />

void egads_paretovariate(prngctx_t *ctx, double *out, double alpha, int *error);<br />

void egads_weibullvariate(prngctx_t *ctx, double *out, double alpha, double beta,<br />

int *error);<br />

void egads_expovariate(prngctx_t *ctx, double *out, double lambda, int *error);<br />

void egads_betavariate(prngctx_t *ctx, double *out, double alpha, double beta,<br />

int *error);<br />

void egads_cunifvariate(prngctx_t *ctx, double *out, double mean, double arc,<br />

int *error);<br />

The egads_randreal( ) function produces a real number between 0 and 1 (inclusive)<br />

that is uniformly distributed across that space. To get a real number in a particular<br />

range, use the function egads_randuniform( ). For those needing random data in a<br />

nonuniform distribution, there are numerous functions in the previous API to produce<br />

random floats in various common distributions. The semantics for these functions<br />

should be obvious to anyone who is already familiar with the particular<br />

distribution.<br />

void egads_randstring(prngctx_t *ctx, char *out, int len, int *error);<br />

The function egads_randstring( ) generates a random string that can contain any<br />

printable character. That is, it produces characters between ASCII 33 and ASCII 126<br />

(inclusive) and thus contains no whitespace characters. The output buffer must be<br />

allocated by the caller, and it must be at least as long as the specified length plus an<br />

additional byte to accommodate the terminating zero that the function will write to<br />

the buffer.<br />

void egads_randfname(prngctx_t *ctx, char *out, int len, int *error);<br />

The function egads_randfname( ) produces a random string suitable for use as a filename.<br />

Generally, you are expected to concatenate the generated string with a base<br />

path. This function expects the destination buffer to be allocated already, and to be<br />

allocated with enough space to hold the string plus a terminating NULL, which this<br />

function will add.<br />

602 | Chapter 11: Random Numbers<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!