23 long safe_high = high;
25 if (safe_high != LONG_MAX) {
29 if (safe_high <= low) {
32 return (low + (
long)(
tw_rand_unif(g) * (safe_high - low)));
39 unsigned long safe_high = high;
41 if (safe_high != ULONG_MAX) {
45 if (safe_high < low) {
48 return (low + (
unsigned long)(
tw_rand_unif(g) * (safe_high - low)));
55 long sucesses, trials;
59 for (trials = 0; trials < N; trials++)
83 double a, b, q, phi, d;
87 a = 1 / sqrt(2 * shape - 1);
97 double V = a * log(U_One / (1 - U_One));
98 double Y = shape * exp(V);
99 double Z = U_One * U_One * U_Two;
100 double W = b + q * V - Y;
102 double temp1 = W + d - phi * Z;
103 double temp2 = log(Z);
105 if (temp1 >= 0 || W >= temp2)
109 }
else if (shape == 1)
114 b = (exp(1) + shape) / exp(1);
119 double P = b * U_One;
123 double Y = pow(P, (1 / shape));
126 if (U_Two <= exp(-Y))
130 double Y = -log((b - P) / shape);
133 if (U_Two <= pow(Y, (shape - 1)))
217 double scale = mean / tgamma( ((
double)1.0 + (
double)1.0/shape));
218 return(scale * pow(-log(
tw_rand_unif(g)), (
double)1.0/shape));
long tw_rand_binomial(tw_rng_stream *g, long N, double P)
unsigned long tw_rand_ulong(tw_rng_stream *g, unsigned long low, unsigned long high)
double tw_rand_pareto(tw_rng_stream *g, double shape, double scale)
tw_rng * tw_rand_init(uint32_t v, uint32_t w)
tw_rng * rng_init(int v, int w)
void tw_error(const char *file, int line, const char *fmt,...) NORETURN
double tw_rand_gamma(tw_rng_stream *g, double shape, double scale)
long tw_rand_geometric(tw_rng_stream *g, double P)
double tw_rand_lognormal(tw_rng_stream *g, double mean, double sd, unsigned int *rng_calls)
double tw_rand_weibull(tw_rng_stream *g, double mean, double shape)
long tw_rand_integer(tw_rng_stream *g, long low, long high)
double tw_rand_normal01(tw_rng_stream *g, unsigned int *rng_calls)
long tw_rand_poisson(tw_rng_stream *g, double Lambda)
double tw_rand_normal_sd(tw_rng_stream *g, double Mu, double Sd, unsigned int *rng_calls)
double tw_rand_exponential(tw_rng_stream *g, double Lambda)