Contact

RANDGAMMA Function (Gnumeric)

Statistical Intermediate Gnumeric Gnumeric 1.1.6

RANDGAMMA(a,b) uses shape first, scale second. The worksheet wrapper requires shape>0 even though the shared gamma helper also serves functions with a zero-shape case.

Verification status: See the evidence and test scope described in this guide. How formula examples are checked

Quick answer: RANDGAMMA(a,b) uses shape first, scale second. The worksheet wrapper requires shape>0 even though the shared gamma helper also serves functions with a zero-shape case.

Syntax

=RANDGAMMA(a,b)

Availability and evidence

  • Introduction: Gnumeric 1.1.6 NEWS explicitly lists this new function. This release-history evidence is separate from a native test of that old version.
  • Source support: Registered in the Gnumeric 1.12.62 random plugin. No retirement is established; the last functioning native application version is unverified.
  • Evidence dates: Official Gnumeric source retained October 13–14, 2026 was reviewed October 15. Mathematical controls were independently recalculated October 15. No native application, compiled Gnumeric helper or random generator was executed.

Parameters and worksheet guard

Both arguments are required. Shape a must be strictly positive; the worksheet callback rejects a≤0 with #NUM! before calling the shared helper. Scale b may be zero but cannot be negative. A valid positive shape with scale 0 returns 0 from the helper’s early-return branch.

Do not copy the shared helper’s zero-shape allowance into this worksheet function’s contract. RANDCHISQ can reach that helper differently, whereas =RANDGAMMA(0,2) is explicitly rejected by the RANDGAMMA wrapper.

For positive parameters, the ideal mean is ab and variance ab². The second parameter is scale, not rate; a rate lambda corresponds to b=1/lambda. Positive noninteger shapes are accepted without truncation.

Complete worksheet setup

Create GammaControls. Put shape 3 in B2 and scale 2 in B3. In D2 enter =RANDGAMMA($B$2,$B$3). It is a changing variate with no fixed expected draw.

In F2 enter =B2*B3, in F3 =B2*B3^2, and in F4 =SQRT(F3). Their independent ideal results are 6, 12, and approximately 3.46410161514, respectively mean, variance and standard deviation. The ideal mode for this shape is (a-1)*b, or 4, distinct from the mean 6.

Deterministic integer-shape controls

For integer shape 3, the inspected small-integer branch multiplies three unit drivers, retries if the product is zero, and takes minus the scale times its logarithm. Put the following supplied triples in A7:C9 and enter =-$B$3*LN(A7*B7*C7) in D7, filling down:

Supplied control inputs Independent reference result
U1=.5, U2=.5, U3=.5 4.15888308336
U1=.25, U2=.5, U3=.75 4.734247228263
U1=.8, U2=.8, U3=.8 1.338861307885

These are controlled triples, not outputs captured from the actual generator. The source uses other branches for larger integer shapes and fractional parts. This simple product formula must not be presented as the exact implementation for every positive a.

Advanced: choose shape and scale from moments

For an illustrative desired mean 10 and standard deviation 5, enter 10 in H2 and 5 in H3. Set H4 to =(H2/H3)^2 and H5 to =H3^2/H2. The results are shape 4 and scale 2.5. =RANDGAMMA(H4,H5) has the corresponding ideal mean 10 and variance 25.

This conversion assumes a positive mean and positive standard deviation. Zero desired spread needs separate handling; dividing by zero to obtain an infinite shape is not a valid worksheet shortcut. The arithmetic does not establish that a gamma distribution fits observed data.

Advanced: shape 1 and fractional shapes

With shape 1, scale 2, the ideal model is exponential with mean 2 and median 2*LN(2), approximately 1.38629436112. The gamma helper’s integer branch rejects a zero product, which differs from RANDEXP’s unfiltered logarithm endpoint. Identical ideal distributions do not prove identical finite generator paths.

With shape 0.5 and scale 2, the ideal mean is 1 and variance 2. The helper separates integer and fractional parts; it does not truncate 0.5 to 0. This case is also the ideal chi-square distribution with one degree of freedom.

Advanced: add compatible gamma variables

Independent ideal gamma variables with shapes 2 and 3 and common scale 2 sum to a gamma variable with shape 5, mean 10 and variance 20. The common scale and independence assumptions are essential.

If the scales differ, adding shape parameters alone does not preserve this simple gamma relationship. If the worksheet adds two references to one random cell, the inputs are perfectly linked rather than independent; the variance calculation changes accordingly.

Error and zero-scale controls

=RANDGAMMA(0,2), =RANDGAMMA(-1,2) and =RANDGAMMA(3,-2) return #NUM!. =RANDGAMMA(3,0) returns 0 without entering the generator branches. =RANDGAMMA(0,0) still returns #NUM! because the worksheet shape guard runs first.

The ordinary positive examples avoid tiny shapes and extreme scales where underflow or overflow needs separate numerical study. Source branch analysis is not a native performance or tail-quality test.

Recalculation and evidence limits

The plugin registers this function as volatile, so recalculation can replace its result. There is no worksheet seed argument in the signature shown here. Exact GUI triggers, saved-file replay and cross-application transfer were not tested. Two calls do not promise the same underlying driver; repeated references to one random cell do not create independent observations.

The supplied driver values and mathematical summaries are deterministic teaching controls. They are not captured random samples. Ideal continuous distributions differ from a finite-resolution generator: rounding, underflow, overflow and endpoint treatment can matter. Non-finite arithmetic is converted to #NUM! by the numeric result constructor. Explicit finite numeric inputs are used throughout; text/blank coercion and locale-sensitive parsing are outside this verification.