We offer a procedure for generating a gamma variate as the cube of a suitably scaled normal variate. It is fast and simple, assuming one has a fast way to generate normal variables. In brief: generate a normal variate <italic>x</italic> and a uniform variate <italic>U</italic> until In (<italic>U</italic>)<0.5<italic>x</italic><supscrpt>2</supscrpt> + <italic>d</italic> - <italic>dv</italic> + <italic>d</italic>ln(italic>v</italic>), then return <italic>dv</italic>. Here, the gamma parameter is α ≥ 1, and <italic>v</italic> = (1 + <italic>x</italic>/ *** with <italic>d</italic> = α - 1/3. The efficiency is high, exceeding 0.951, 0.981, 0.992, 0.996 at α = 1,2,4,8. The procedure can be made to run faster by means of a simple squeeze that avoids the two logarithms most of the time; return <italic>dv</italic> if <italic>U</italic> < 1-0.0331<italic>x</italic><supscrpt>4</supscrpt>. We give a short C program for any α ≥ 1, and show how to boost an α <1 into an α > 1. The gamma procedure is particularly fst for C implementation if the normal variate is generated in-line, via the #define feature. We include such an inline version, based on our ziggurat method. With it, and an inline uniform generator, gamma variates can be produced in 400MHz CPUs at better than 1.3 million per second, with the parameter α changing from call to call.
[1]
George Marsaglia,et al.
The Monty Python Method for Generating Gamma Variables
,
1999
.
[2]
G. Marsaglia,et al.
The Ziggurat Method for Generating Random Variables
,
2000
.
[3]
G. Marsaglia.
The squeeze method for generating gamma variates
,
1977
.
[4]
Do Le Minh,et al.
Generating gamma variates
,
1988,
TOMS.
[5]
George Marsaglia.
The exact-approximation method for generating random variables
,
1984
.
[6]
Russell C. H. Cheng,et al.
Some Simple Gamma Variate Generators
,
1979
.
[7]
L. Devroye.
Non-Uniform Random Variate Generation
,
1986
.
[8]
George Marsaglia,et al.
A Fast, Easily Implemented Method for Sampling from Decreasing or Symmetric Unimodal Density Functions
,
1984
.
[9]
George Marsaglia,et al.
The Monty Python method for generating random variables
,
1998,
TOMS.
[10]
Joachim H. Ahrens,et al.
Generating gamma variates by a modified rejection technique
,
1982,
CACM.
[11]
B. Schmeiser,et al.
Squeeze Methods for Generating Gamma Variates
,
1980
.