32 long safe_high = high;
34 if (safe_high != LONG_MAX) {
38 if (safe_high <= low) {
41 return (low + (
long)(
tw_rand_unif(g) * (safe_high - low)));
48 unsigned long safe_high = high;
50 if (safe_high != ULONG_MAX) {
54 if (safe_high < low) {
57 return (low + (
unsigned long)(
tw_rand_unif(g) * (safe_high - low)));
64 long sucesses, trials;
68 for (trials = 0; trials < N; trials++)
92 double a, b, q, phi, d;
96 a = 1 / sqrt(2 * shape - 1);
106 double V = a * log(U_One / (1 - U_One));
107 double Y = shape * exp(V);
108 double Z = U_One * U_One * U_Two;
109 double W = b + q * V - Y;
111 double temp1 = W + d - phi * Z;
112 double temp2 = log(Z);
114 if (temp1 >= 0 || W >= temp2)
118 }
else if (shape == 1)
123 b = (exp(1) + shape) / exp(1);
128 double P = b * U_One;
132 double Y = pow(P, (1 / shape));
135 if (U_Two <= exp(-Y))
139 double Y = -log((b - P) / shape);
142 if (U_Two <= pow(Y, (shape - 1)))
226 double scale =
mean / tgamma( ((
double)1.0 + (
double)1.0/shape));
227 return(scale * pow(-log(
tw_rand_unif(g)), (
double)1.0/shape));
tw_rng * rng_core_init(int v, int w)
tw_rng * rng_init(int v, int w)
void tw_error(const char *file, int line, const char *fmt,...)
tw_rng * tw_rand_core_init(uint32_t v, uint32_t w)
double tw_rand_gamma(tw_rng_stream *g, double shape, double scale)
double tw_rand_normal_sd(tw_rng_stream *g, double Mu, double Sd, unsigned int *rng_calls)
long tw_rand_integer(tw_rng_stream *g, long low, long high)
unsigned long tw_rand_ulong(tw_rng_stream *g, unsigned long low, unsigned long high)
long tw_rand_binomial(tw_rng_stream *g, long N, double P)
double tw_rand_lognormal(tw_rng_stream *g, double mean, double sd, unsigned int *rng_calls)
long tw_rand_geometric(tw_rng_stream *g, double P)
double tw_rand_weibull(tw_rng_stream *g, double mean, double shape)
tw_rng * tw_rand_init(uint32_t v, uint32_t w)
double tw_rand_exponential(tw_rng_stream *g, double Lambda)
long tw_rand_poisson(tw_rng_stream *g, double Lambda)
double tw_rand_normal01(tw_rng_stream *g, unsigned int *rng_calls)
double tw_rand_pareto(tw_rng_stream *g, double shape, double scale)