# Chapter 7Random Number Distributions

This chapter describes the functions for generating random variates and computing their probability distributions provided by the PLT Scheme Science Collection.

The functions described in this chapter are defined in the random-distributions sub-collection of the science collection. All of the modules in the random-distributions sub-collection can be made available using the form:

```(require (planet "random-distributions.ss"
("williams" "science.plt")))
```

The random distribution graphics are provided as separate modules. To include the random distribution graphics routines, use the following form:

```(require (planet "random-distributions-with-graphics.ss"
("williams" "science.plt")))
```

The individual modules in the random-distributions sub-collection can also be made available as described in the sections below.

## 7.1  The Beta Distribution

The beta distribution functions are defined in the beta.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:

```(require (planet "beta.ss" ("williams" "science.plt")
"random-distributions"))
```

### 7.1.1  Random Variates from the Beta Distribution

random-beta

 Function: ```(random-beta s a b) (random-beta a b)``` Contract: ```(case-> (-> random-source? real? real? (real-in 0.0 1.0)) (-> real? real? (real-in 0.0 1.0)))```
This function returns a random variate from the beta distribution with parameters a and b using the random source s or (current-random-source) if s is not provided.

Example: Histogram of random variates from the beta distribution with parameters 2.0 and 3.0.

```(require (planet "beta.ss" ("williams" "science.plt")
"random-distributions"))
(require (planet "histogram-with-graphics.ss"
("williams" "science.plt")))

(let ((h (make-histogram-with-ranges-uniform 40 0.0 1.0)))
(do ((i 0 (+ i 1)))
((= i 10000) (void))
(histogram-increment! h (random-beta 2.0 3.0)))
(histogram-plot h "Histogram of Beta Distribution"))
```

Figure 20 shows the resulting histogram.

### 7.1.2  Beta Distribution Density Functions

beta-pdf

 Function: `(beta-pdf x a b)` Contract: `(-> real? real? real? (>=/c 0.0))`
This function computes the probability density, p(x), at x for the beta distribution with parameters a and b.

beta-cdf

 Function: `(beta-cdf x a b)` Contract: `(-> real? real? real? (real-in 0.0 1.0))`
This function computes the cummulative density, d(x), at x for the beta distribution with parameters a and b.

### 7.1.3  Beta Distribution Graphics

The beta distribution graphics functions are defined in the file beta-graphics.ss in the random-distributions sub-collection of the science collection and are made available using the form:

```(require (planet "beta-graphics.ss" ("williams" "science.plt")
"random-distributions"))
```

beta-plot

 Function: `(beta-plot a b)` Contract: `(-> real? real? any)`
This function returns a plot of the probability density and cummulative density of the beta distribution with parameters a and b. The plot is produced by the plot collection provided with PLT Scheme (PLoT Scheme).

Example: Plot of probability density and cummulative density of the beta distribution with parameters 2.0 and 3.0.

```(require (planet "beta-graphics.ss" ("williams" "science.plt")
"random-distributions"))
(beta-plot 2.0 3.0)
```

Figure 21 shows the resulting plot.

## 7.2  The Bivariate Gaussian Distribution

The bivariate Gaussian distribution functions are defined in the bivariate-gaussian.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:

```(require (planet "bivatiate-gaussian.ss" ("williams" "science.plt")
"random-distributions"))
```

### 7.2.1  Random Variates from the Bivariate Gaussian Distribution

random-bivariate-gaussian

 Function: ```(random-bivariate-gaussian s sigma-x sigma-y rho) (random-bivariate-gaussian sigma-x sigma-y rho)``` Contract: ```(case-> (-> random-source? (>=/c 0.0) (>=/c 0.0) (real-in -1.0 1.0) (values real? real?)) (-> (>=/c 0.0) (>=/c 0.0) (real-in -1.0 1.0) (values real? real?))```
This function returns a pair of correlated Gaussian variates, with mean 0, correlation coefficient rho, and standard deviations sigma-x and sigma-y in the x and y directions using the random source s or (current-random-source) if s is not provided. The correlation coefficient rho must lie between - 1 and 1.

Example: Histogram of random variates from the bivariate Gaussian distribution standard deviations 1.0 and 1.0 in the x and y directions and correlation coefficient 0.0.

```(require (planet "bivariate-gaussian.ss" ("williams" "science.plt")
"random-distributions"))
(require (planet "histogram-2d-with-graphics.ss"
("williams" "science.plt")))

(let ((h (make-histogram-2d-with-ranges-uniform
20 20 -3.0 3.0 -3.0 3.0)))
(do ((i 0 (+ i 1)))
((= i 10000) (void))
(let-values (((x y) (random-bivariate-gaussian 1.0 1.0 0.0)))
(histogram-2d-increment! h x y)))
(histogram-2d-plot h "Histogram of Bivariate Gaussian Distribution"))
```

Figure 22 shows the resulting 2D histogram.

### 7.2.2  Bivariate Gaussian Distribution Density Functions

bivariate-gaussian-pdf

 Function: `(bivariate-gaussian-pdf x y sigma-x sigma-y rho)` Contract: `(-> real? real? (>=/c 0.0 (>=/c 0.0) (real-in -1.0 0.0) real?)`
This function computes the probability density, p(x, y), at (x, y) for the bivariate Gaussian distribution with standard deviations sigma-x and sigma-y in the x and y directions and correlation coefficient rho.

### 7.2.3  Bivariate Gaussian Distribution Graphics

The bivariate Gaussian distribution graphics functions are defined in the file bivariate- gaussian-graphics.ss in the random-distributions sub-collection of the science collection and are made available using the form:

```(require (planet "bivariate-gaussian-graphics.ss"
("williams" "science.plt")
"random-distributions"))
```

bivariate-gaussian-plot

 Function: `(bivariate-gaussian-plot sigma-x sigma-y rho)` Contract: `(-> (>=/c 0.0) (>=/c 0.0) (real-in -1.0 1.0) any)`
This function returns a plot of the probability density of the bivariate Gaussian distribution with standard deviations sigma-x and sigma-y in the x and y directions and correlation coefficient rho. The plot is produced by the plot collection provided with PLT Scheme (PLoT Scheme).

Example: Plot of probability density of the bivariate Gaussian distribution with standard deviations 1.0 and 1.0 in the x and y directions and correlation coefficient 0.0.

```(require (planet "bivariate-gaussian-graphics.ss"
("williams" "science.plt")
"random-distributions"))
(bivariate-gaussian-plot 1.0 1.0 0.0)
```

Figure 23 shows the resulting plot.

## 7.3  The Chi-Squared Distribution

The chi-squared distribution functions are defined in the chi-squared.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:

```(require (planet "chi-squared.ss" ("williams" "science.plt")
"random-distributions"))
```

### 7.3.1  Random Variates from the Chi-Squared Distribution

random-chi-squared

 Function: ```(random-chi-squared s nu) (random-chi-squared nu)``` Contract: ```(case-> (-> random-source? real? (>=/c 0.0)) (-> real? (>=/c 0.0)))```
This function returns a random variate from the chi squared distribution with nu degrees of freedom using the random source s or (current-random-source) if s is not provided.

Example: Histogram of random variates from the chi squared distribution with 3.0 degrees of freedom.

```(require (planet "chi-squared.ss" ("williams" "science.plt")
"random-distributions"))
(require (planet "histogram-with-graphics.ss"
("williams" "science.plt")))

(let ((h (make-histogram-with-ranges-uniform 40 0.0 10.0)))
(do ((i 0 (+ i 1)))
((= i 10000) (void))
(histogram-increment! h (random-chi-squared 3.0)))
(histogram-plot h "Histogram of Chi Squared Distribution"))
```

Figure 24 shows the resulting histogram.

### 7.3.2  Chi-Squared Distribution Density Functions

chi-squared-pdf

 Function: `(chi-squared-pdf x nu)` Contract: `(-> real? real? (>=/c 0.0))`
This function computes the probability density, p(x), at x for the chi squared distribution with nu degrees of freedom.

chi-squared-cdf

 Function: `(chi-squared-cdf x nu)` Contract: `(-> real? real? (real-in 0.0 1.0))`
This function computes the cummulative density, d(x), at x for the chi squared distribution with nu degrees of freedom.

### 7.3.3  Chi-Squared Distribution Graphics

The chi squared distribution graphics functions are defined in the file chi-squared-graphics.ss in the random-distributions sub-collection of the science collection and are made available using the form:

```(require (planet "chi-squared-graphics.ss"
("williams" "science.plt")
"random-distributions"))
```

chi-squared-plot

 Function: `(chi-squared-plot nu)` Contract: `(-> real? any)`
This function returns a plot of the probability density and cummulative density of the chi squared distribution with nu degrees of freedom. The plot is produced by the plot collection provided with PLT Scheme (PLoT Scheme).

Example: Plot of probability density and cummulative density of the chi squared distribution with 3.0 degrees of freedom.

```(require (planet "chi-squared-graphics.ss"
("williams" "science.plt")
"random-distributions"))
(chi-squared-plot 3.0)
```

Figure 25 shows the resulting plot.

## 7.4  The Exponential Distribution

The exponential distribution functions are defined in the exponential.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:

```(require (planet "exponential.ss" ("williams" "science.plt")
"random-distributions"))
```

### 7.4.1  Random Variates from the Exponential Distribution

random-exponential

 Function: ```(random-exponential s mu) (random-exponential mu)``` Contract: ```(case-> (-> random-source? (>/c 0.0) (>=/c 0.0)) (-> (>/c 0.0) (>=/c 0.0)))```
This function returns a random variate from the exponential distribution with mean mu using the random source s or (current-random-source) if s is not provided.

Example: Histogram of random variates from the exponential distribution with mean 1.0.

```(require (planet "exponential.ss" ("williams" "science.plt")
"random-distributions"))
(require (planet "histogram-with-graphics.ss"
("williams" "science.plt")))

(let ((h (make-histogram-with-ranges-uniform 40 0.0 8.0)))
(do ((i 0 (+ i 1)))
((= i 10000) (void))
(histogram-increment! h (random-exponential 1.0)))
(histogram-plot h "Histogram of Exponential Distribution"))
```

Figure 26 shows the resulting histogram.

### 7.4.2  Exponential Distribution Density Functions

exponential-pdf

 Function: `(exponential-pdf x mu)` Contract: `(-> real? real? (>=/c 0.0))`
This function computes the probability density, p(x), at x for the exponential distribution with mean mu.

exponential-cdf

 Function: `(exponential-cdf x mu)` Contract: `(-> real? real? (real-in 0.0 1.0))`
This function computes the cumulative density, d(x), at x for the exponential distribution with mean mu.

### 7.4.3  Exponential Distribution Graphics

The exponential distribution graphics functions are defined in the file exponential-graphics.ss in the random-distributions sub-collection of the science collection and are made available using the form:

```(require (planet "exponential-graphics.ss"
("williams" "science.plt")
"random-distributions"))
```

exponential-plot

 Function: `(exponential-plot mu)` Contract: `(-> (>=/c 0.0) any)`
This function returns a plot of the probability density and cumulative density of the exponential distribution with mean mu. The plot is produced by the plot collection provided with PLT Scheme (PLoT Scheme).

Example: Plot of probability density and cummulative density of the exponential distribution with mean 3.0.

```(require (planet "exponential-graphics.ss"
("williams" "science.plt")
"random-distributions"))
(exponential-plot 3.0)
```

Figure 27 shows the resulting plot.

## 7.5  The F-Distribution

The F-distribution functions are defined in the f-distribution.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:

```(require (planet "f-distribution.ss" ("williams" "science.plt")
"random-distributions"))
```

### 7.5.1  Random Variates from the F-Distribution

random-f-distribution

 Function: ```(random-f-distribution s nu1 nu2) (random-f-distribution nu1 nu2)``` Contract: ```(case-> (-> random-source? real? real? (>=/c 0.0)) (-> real? real? (>=/c 0.0)))```
This function returns a random variate from the F-distribution with nu1 and nu2 degrees of freedom using the random source s or (current-random-source) if s is not provided.

Example: Histogram of random variates from the F-distribution with 2.0 and 3.0 degrees of freedom.

```(require (planet "f-distribution.ss" ("williams" "science.plt")
"random-distributions"))
(require (planet "histogram-with-graphics.ss"
("williams" "science.plt")))

(let ((h (make-histogram-with-ranges-uniform 40 0.0 10.0)))
(do ((i 0 (+ i 1)))
((= i 10000) (void))
(histogram-increment! h (random-f-distribution 2.0 3.0)))
(histogram-plot h "Histogram of F-Distribution"))
```

Figure 28 shows the resulting histogram.

### 7.5.2  F-Distribution Density Functions

f-distribution-pdf

 Function: `(f-distribution-pdf x nu1 nu2)` Contract: `(-> real? real? real? (>=/c 0.0))`
This function computes the probability density, p(x), at x for the F-distribution with nu1 and nu2 degrees of freedom.

f-distribution-cdf

 Function: `(f-distribution-pdf x nu1 nu2)` Contract: `(-> real? real? real? (real-in 0.0 1.0))`
This function computes the cummulative density, d(x), at x for the F-distribution with nu1 and nu2 degrees of freedom.

### 7.5.3  F-Distribution Graphics

The exponential distribution graphics functions are defined in the file f-distribution-graphics.ss in the random-distributions sub-collection of the science collection and are made available using the form:

```(require (planet "f-distribution-graphics.ss"
("williams" "science.plt")
"random-distributions"))
```

f-distribution-plot

 Function: `(f-distribution-plot nu1 nu2)` Contract: `(-> (>=/c 0.0) any)`
This function returns a plot of the probability density of the F-distribution with nu1 and nu2 degrees of freedom. The plot is produced by the plot collection provided with PLT Scheme (PLoT Scheme).

Example: Plot of probability density of the F-distribution distribution with 2.0 and 3.0 degrees of freedom.

```(require (planet "f-distribution-graphics.ss"
("williams" "science.plt" 2 0)
"random-distributions"))
(f-distribution-plot 2.0 3.0)
```

Figure 29 shows the resulting plot.

## 7.6  The Flat (Uniform) Distribution

The flat (uniform) distribution functions are defined in the flat.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:

```(require (planet "flat.ss" ("williams" "science.plt")
"random-distributions"))
```

### 7.6.1  Random Variates from the Flat Distribution

random-flat

 Function: ```(random-flat s a b) (random-flat a b)``` Contract: ```(case-> (->r ((s random-source?) (a real?) (b (>/c a)) real?) (->r ((a real?) (b (>/c a)) real?))```
This function returns a random variate from the flat (uniform) distribution from a to b using the random source s or (current-random-source) if s is not provided.

Example: Histogram of random variates from the flat (uniform) distribution from 1.0 to 4.0.

```(require (planet "flat.ss" ("williams" "science.plt")
"random-distributions"))
(require (planet "histogram-with-graphics.ss"
("williams" "science.plt")))

(let ((h (make-histogram-with-ranges-uniform 40 1.0 4.0)))
(do ((i 0 (+ i 1)))
((= i 10000) (void))
(histogram-increment! h (random-flat 1.0 4.0)))
(histogram-plot h "Histogram of Flat (Uniform) Distribution"))
```

Figure 30 shows the resulting histogram.

### 7.6.2  Flat Distribution Density Functions

flat-pdf

 Function: `(flat-pdf x a b)` Contract: ```(->r ((x real?) (a real?) (b (>/c a))) (>=/c 0.0))```
This function computes the probability density, p(x), at x for the flat (uniform) distribution from a to b.

flat-cdf

 Function: `(flat-cdf x a b)` Contract: ```(->r ((x real?) (a real?) (b (>/c a))) (real-in 0.0 1.0))```
This function computes the cumulative density, d(x), at x for the flat (uniform) distribution from a to b.

### 7.6.3  Flat Distribution Graphics

The flat (uniform) distribution graphics functions are defined in the file flat-graphics-.ss in the random-distributions sub-collection of the science collection and are made available using the form:

```(require (planet "flat-graphics.ss" ("williams" "science.plt")
"random-distributions"))
```

flat-plot

 Function: `(flat-plot a b)` Contract: ```(->r ((a real?) (b (>/c a))) any)```
This function returns a plot of the probability density of the flat distribution from a to b. The plot is produced by the plot collection provided with PLT Scheme (PLoT Scheme).

Example: Plot of probability density and cumulative density of the flat (uniform) distribution from 1.0 to 4.0.

```(require (planet "flat-graphics.ss" ("williams" "science.plt")
"random-distributions"))
(flat-plot 1.0 4.0)
```

Figure 31 shows the resulting plot.

## 7.7  The Gamma Distribution

The gamma distribution functions are defined in the gamma.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:

```(require (planet "gamma.ss" ("williams" "science.plt")
"random-distributions"))
```

### 7.7.1  Random Variates from the Gamma Distribution

random-gamma

 Function: `(random-gamma s a b)(random-gamma a b)` Contract: ```(case-> (-> random-source? (>/c 0.0) real? (>=/c 0.0)) (-> (>/c 0.0 real? (>=/c 0.0)))```
This function returns a random variate from the gamma distribution with parameters a and b using the random source s or (current-random-source) if s is not provided.

Example: Histogram of random variates from the gamma distribution with parameters 3.0 and 3.0.

```(require (planet "gamma.ss" ("williams" "science.plt")
"random-distributions"))
(require (planet "histogram-with-graphics.ss"
("williams" "science.plt")))

(let ((h (make-histogram-with-ranges-uniform 40 0.0 24.0)))
(do ((i 0 (+ i 1)))
((= i 10000) (void))
(histogram-increment! h (random-gamma 3.0 3.0)))
(histogram-plot h "Histogram of Gamma Distribution"))
```

Figure 32 shows the resulting histogram.

### 7.7.2  Gamma Distribution Density Functions

gamma-pdf

 Function: `(gamma-pdf x a b)` Contract: `(-> real? (>/c 0.0) real? (>=/c 0.0))`
This function computes the probability density, p(x), at x for the gamma distribution with parameters a and b.

gamma-cdf

 Function: `(gamma-cdf x a b)` Contract: `(-> real? (>/c 0.0) real? (real-in 0.0 1.0))`
This function computes the cummulative density, d(x), at x for the gamma distribution with parameters a and b.

### 7.7.3  Gamma Distribution Graphics

The gamma distribution graphics functions are defined in the file gamma-graphics.ss in the random-distributions sub-collection of the science collection and are made available using the form:

```(require (planet "gamma-graphics.ss" ("williams" "science.plt")
"random-distributions"))
```

gamma-plot

 Function: `(gamma-plot a b)` Contract: `(-> (>/c 0.0) real?)`
This function returns a plot of the probability density and cummulative density of the gamma distribution with parameters a and b. The plot is produced by the plot collection provided with PLT Scheme (PLoT Scheme).

Example: Plot of probability density and cummulative density of the gamma distribution with parameters 3.0 and 3.0.

```(require (planet "gamma-graphics.ss" ("williams" "science.plt")
"random-distributions"))
(gamma-plot 3.0 3.0)
```

Figure 33 shows the resulting plot.

## 7.8  The Gaussian Distribution

The Gaussian distribution functions are defined in the gaussian.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:

```(require (planet "gaussian.ss" ("williams" "science.plt")
"random-distributions"))
```

### 7.8.1  Random Variates from the Gaussian Distribution

random-gaussian

 Function: ```(random-gaussian s mu sigma) (random-gaussian mu sigma)``` Contract: ```(case-> (-> random-source? real? (>=/c 0.0) real?) (-> real? (>=/c 0.0) real?))```
This function returns a random variate from the Gaussian (normal) distribution with mean mu and standard deviation sigma using the random source s or (current-random-source) if s is not provided. This function uses the Box-Mueller algorithm that requires two calls to the random source s.

Example: Histogram of random variates from the Gaussian (normal) distribution with mean 10.0 and standard deviation 2.0.

```(require (planet "gaussian.ss" ("williams" "science.plt")
"random-distributions"))
(require (planet "histogram-with-graphics.ss"
("williams" "science.plt")))

(let ((h (make-histogram-with-ranges-uniform 40 4.0 16.0)))
(do ((i 0 (+ i 1)))
((= i 10000) (void))
(histogram-increment! h (random-gaussian 10.0 2.0)))
(histogram-plot h "Histogram of Gaussian Distribution"))
```

Figure 34 shows the resulting histogram.

random-unit-gaussian

 Function: ```(random-unit-gaussian s) (random-unit-gaussian)``` Contract: ```(case-> (-> random-source? real?) (-> real?))```
This function returns a random variate from the Gaussian (normal) distribution with mean 0.0 and standard deviation 1.0 using the random source s or (current-random-source) if s is not provided. This function uses the Box-Mueller algorithm that requires two calls to the random source s.

Example: Histogram of random variates from the unit Gaussian (normal) distribution.

```(require (planet "gaussian.ss" ("williams" "science.plt")
"random-distributions"))
(require (planet "histogram-with-graphics.ss"
("williams" "science.plt")))

(let ((h (make-histogram-with-ranges-uniform 40 -3.0 3.0)))
(do ((i 0 (+ i 1)))
((= i 10000) (void))
(histogram-increment! h (random-unit-gaussian)))
(histogram-plot h "Histogram of Unit Gaussian Distribution"))
```

Figure 35 shows the resulting histogram.

random-gaussian-ratio-method

 Function: ```(random-gaussian-ratio-method s mu sigma) (random-gaussian-ratio-method mu sigma)``` Contract: ```(case-> (-> random-source? real? (>=/c 0.0) real?) (-> real? (>=/c 0.0) real?))```
This function returns a random variate from the Gaussian (normal) distribution with mean mu and standard deviation sigma using the random source s or (current-random-source) if s is not provided. This function uses the Kinderman-Monahan ratio method.

random-unit-gaussian-ratio-method

 Function: ```(random-unit-gaussian-ratio-method s) (random-unit-gaussian-ratio-method)``` Contract: ```(case-> (-> random-source? real?) (-> real?))```
This function returns a random variate from the Gaussian (normal) distribution with mean 0.0 and standard deviation 1.0 using the random source s or (current-random-source) if s is not provided. This function uses the Kinderman-Monahan ratio method.

### 7.8.2  Gaussian Distribution Density Functions

gaussian-pdf

 Function: `(gaussian-pdf x mu sigma)` Contract: `(-> real? real? (>/c 0.0) (>=/c 0.0))`
This function computes the probability density, p(x), at x for the Gaussian (normal) distribution with mean mu and standard deviation sigma.

gaussian-cdf

 Function: `(gaussian-cdf x mu sigma)` Contract: `(-> real? real? (>/c 0.0) (real-in 0.0 1.0))`
This function computes the cumulative density, d(x), at x for the Gaussian (normal) distribution with mean mu and standard deviation sigma.

unit-gaussian-pdf

 Function: `(unit-gaussian-pdf x)` Contract: `(-> real? (>=/c 0.0))`
This function computes the probability density, p(x), at x for the Gaussian (normal) distribution with mean 0.0 and standard deviation 1.0.

unit-gaussian-pdf

 Function: `(unit-gaussian-cdf x)` Contract: `(-> real? (real-in 0.0 1.0))`
This function computes the cumulative density, d(x), at x for the Gaussian (normal) distribution with mean 0.0 and standard deviation 1.0.

### 7.8.3  Gaussian Distribution Graphics

The Gaussian distribution graphics functions are defined in the file gaussian-graphics-.ss in the random-distributions sub-collection of the science collection and are made available using the form:

```(require (planet "gaussian-graphics.ss" ("williams" "science.plt")
"random-distributions"))
```

gaussian-plot

 Function: `(gaussian-plot mu sigma)` Contract: `(-> real? (>/c 0.0) any)`
This function returns a plot of the probability density and cumulative density of the Gaussian (normal) distribution with mean mu and standard deviation sigma. The plot is produced by the plot collection provided with PLT Scheme (PLoT Scheme).

Example: Plot of probability density and cumulative density of the Gaussian (normal) distribution with mean 10.0 and standard deviation 2.0.

```(require (planet "gaussian-graphics.ss" ("williams" "science.plt")
"random-distributions"))
(gaussian-plot 10.0 2.0)
```

Figure 36 shows the resulting plot.

unit-gaussian-plot

 Function: `(unit-gaussian-plot)` Contract: `(-> any)`
This function returns a plot of the probability density and cumulative density of the Gaussian (normal) distribution with mean 0.0 and standard deviation 1.0. The plot is produced by the plot collection provided with PLT Scheme (PLoT Scheme).

Example: Plot of probability density and cumulative density of the Gaussian (normal) distribution with mean 0.0 and standard deviation 1.0.

```(require (planet "gaussian-graphics.ss" ("williams" "science.plt")
"random-distributions"))
(unit-gaussian-plot)
```

Figure 37 shows the resulting plot.

## 7.9  The Gaussian Tail Distribution

The Gaussian tail distribution functions are defined in the gaussian-tail.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:

```(require (planet "gaussian-tail.ss" ("williams" "science.plt")
"random-distributions"))
```

### 7.9.1  Random Variates from the Gaussian Tail Distribution

random-gaussian-tail

 Function: ```(random-gaussian-tail s a mu sigma) (random-gaussian-tail a mu sigma``` Contract: ```(case-> (-> random-source? real? real? (>/c 0.0) real?) (-> real? real? (>/c 0.0) real?))```
This function returns a random variate from the upper tail of the Gaussian distribution with mean mu and standard deviation sigma using the random source s or (current-random-source) if s is not provided. The value returned is larger than the lower limit a, which must be greater than the mean mu.

random-unit-gaussian-tail

 Function: ```(random-unit-gaussian-tail s a) (random-unit-gaussian-tail a``` Contract: ```(case-> (-> random-source? (>/c 0.0) (>/c 0.0)) (-> (>/c 0.0)))```
This function returns a random variate from the upper tail of the Gaussian distribution with mean 0 and standard deviation 1 using the random source s or (current-random-source) if s is not provided. The value returned is larger than the lower limit a, which must be positive.

Example: Histogram of random variates from the upper tail greater than 16.0 of the Gaussian distribution with mean 10.0 and standard deviation 2.0.

```(require (planet "gaussian-tail.ss" ("williams" "science.plt")
"random-distributions"))
(require (planet "histogram-with-graphics.ss"
("williams" "science.plt")))

(let ((h (make-histogram-with-ranges-uniform 40 16.0 22.0)))
(do ((i 0 (+ i 1)))
((= i 10000) (void))
(histogram-increment! h (random-gaussian-tail 16.0 10.0 2.0)))
(histogram-plot h "Histogram of Gaussian Tail Distribution"))
```

Figure 38 shows the resulting histogram.

Example: Histogram of random variates from the upper tail greater than 3.0 of the unit Gaussian distribution.

```(require (planet "gaussian-tail.ss" ("williams" "science.plt")
"random-distributions"))
(require (planet "histogram-with-graphics.ss"
("williams" "science.plt")))

(let ((h (make-histogram-with-ranges-uniform 40 3.0 6.0)))
(do ((i 0 (+ i 1)))
((= i 10000) (void))
(histogram-increment! h (random-unit-gaussian-tail 3.0)))
(histogram-plot h "Histogram of Unit Gaussian Tail Distribution"))
```

Figure 39 shows the resulting histogram.

### 7.9.2  Gaussian Tail Distribution Density Functions

gaussian-tail-pdf

 Function: `(gaussian-tail-pdf x a mu sigma)` Contract: `(-> real? real? real? (>/c 0.0) (>=/c 0.0))`
This function computes the probability density, p(x), at x for the upper tail greater than a of the Gaussian distribution with mean mu and standard deviation sigma.

unit-gaussian-tail-pdf

 Function: `(unit-gaussian-tail-pdf x a)` Contract: `(-> real? (>=/c 0.0) (>=/c 0.0))`
This function computes the probability density, p(x), at x for the upper tail greater than a of the Gaussian distribution with mean mu and standard deviation sigma.

### 7.9.3  Gaussian Tail Distribution Graphics

The Gaussian tail distribution graphics functions are defined in the file gaussian- tail-graphics.ss in the random-distributions sub-collection of the science collection and are made available using the form:

```(require (planet "gaussian-tail-graphics.ss"
("williams" "science.plt")
"random-distributions"))
```

gaussian-tail-plot

 Function: `(gaussian-tail-plot a mu sigma)` Contract: `(-> real? real? (>/c 0.0) any)`
This function returns a plot of the probability density of the upper tail greater than a of the Gaussian distribution with mean mu and standard deviation sigma. The plot is produced by the plot collection provided with PLT Scheme (PLoT Scheme).

Example: Plot of probability density and cumulative density of the upper tail greater than 16.0 of the Gaussian distribution with mean 10.0 and standard deviation 2.0.

```(require (planet "gaussian-tail-graphics.ss"
("williams" "science.plt" 2 0)
"random-distributions"))
(gaussian-tail-plot 16.0 10.0 2.0)
```

Figure 40 shows the resulting plot.

unit-gaussian-tail-plot

 Function: `(unit-gaussian-tail-plot a)` Contract: `(-> (>=/c 0.0) any)`
This function returns a plot of the probability density of the upper tail greater than a of the Gaussian distribution with mean 0.0 and standard deviation 1.0. The plot is produced by the plot collection provided with PLT Scheme (PLoT Scheme).

Example: Plot of probability density and cumulative density of the upper tail greater than 3.0 of the Gaussian distribution with mean 0.0 and standard deviation 1.0.

```(require (planet "gaussian-tail-graphics.ss"
("williams" "science.plt")
"random-distributions"))
(unit-gaussian-tail-plot 3.0)
```

Figure 41 shows the resulting plot.

## 7.10  The Log Normal Distribution

The log normal distribution functions are defined in the lognormal.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:

```(require (planet "lognormal.ss" ("williams" "science.plt")
"random-distributions"))
```

### 7.10.1  Random Variates from the Log Normal Distribution

random-lognormal

 Function: ```(random-lognormal s mu sigma) (random-lognormal mu sigma)``` Contract: ```(case-> (-> random-source? real? (>=/c 0.0) real?) (-> real? real?))```
This function returns a random variate from the log normal distribution with mean mu and standard deviation sigma using the random source s or (current-random-source) if s is not provided.

Example: Histogram of random variates from the log normal distribution with mean 0.0 and standard deviation 1.0.

```(require (planet "lognormal.ss" ("williams" "science.plt")
"random-distributions"))
(require (planet "histogram-with-graphics.ss"
("williams" "science.plt")))

(let ((h (make-histogram-with-ranges-uniform 40 0.0 6.0)))
(do ((i 0 (+ i 1)))
((= i 10000) (void))
(histogram-increment! h (random-lognormal 0.0 1.0)))
(histogram-plot h "Histogram of Log Normal Distribution"))
```

Figure 42 shows the resulting histogram.

### 7.10.2  Log Normal Distribution Density Functions

lognormal-pdf

 Function: `(lognormal-pdf x mu sigma)` Contract: `(-> real? real? (>/c 0.0) (>=/c 0.0))`
This function computes the probability density, p(x), at x for the log normal distribution with mean mu and standard deviation sigma.

lognormal-cdf

 Function: `(lognormal-cdf x mu sigma)` Contract: `(-> real? real? (>/c 0.0) (real-in 0.0 1.0))`
This function computes the cumulative density, d(x), at x for the log normal distribution with mean mu and standard deviation sigma.

### 7.10.3  Log Normal Distribution Graphics

The log normal distribution graphics functions are defined in the file lognormal-graphics.ss in the random-distributions sub-collection of the science collection and are made available using the form:

```(require (planet "lognormal-graphics.ss"
("williams" "science.plt")
"random-distributions"))
```

lognormal-plot

 Function: `(lognormal-plot mu sigma)` Contract: `(-> real? (>/c 0.0) any)`
This function returns a plot of the probability density and cumulative density of the log normal distribution with mean mu and standard deviation sigma. The plot is produced by the plot collection provided with PLT Scheme (PLoT Scheme).

Example: Plot of probability density and cumulative density of the log normal distribution with mean 0.0 and standard deviation 1.0.

```(require (planet "lognormal-graphics.ss"
("williams" "science.plt")
"random-distributions"))
(lognormal-plot 0.0 1.0)
```

Figure 43 shows the resulting plot.

## 7.11  The Pareto Distribution

The Pareto distribution functions are defined in the pareto.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:

```(require (planet "pareto.ss" ("williams" "science.plt")
"random-distributions"))
```

### 7.11.1  Random Variates from the Pareto Distribution

random-pareto

 Function: ```(random-pareto s a b) (random-pareto a b)``` Contract: ```(case-> (-> random-source? real? real? real?) (-> real? real? real?))```
This function returns a random variate from the Pareto distribution with parameters a and b using the random source s or (current-random-source) if s is not provided.

Example: Histogram of random variates from the Pareto distribution with parameters 1.0 and 1.0.

```(require (planet "pareto.ss" ("williams" "science.plt")
"random-distributions"))
(require (planet "histogram-with-graphics.ss"
("williams" "science.plt")))

(let ((h (make-histogram-with-ranges-uniform 40 1.0 21.0)))
(do ((i 0 (+ i 1)))
((= i 10000) (void))
(histogram-increment! h (random-pareto 1.0 1.0)))
(histogram-plot h "Histogram of Pareto Distribution"))
```

Figure 44 shows the resulting histogram.

### 7.11.2  Pareto Distribution Density Functions

pareto-pdf

 Function: `(pareto-pdf x a b)` Contract: `(-> real? real? real? (>=/c 0.0))`
This function computes the probability density, p(x), at x for the Pareto distribution with parameters a and b.

pareto-cdf

 Function: `(pareto-cdf x a b)` Contract: `(-> real? real? real? (real-in 0.0 1.0))`
This function computes the cumulative density, d(x), at x for the Pareto distribution with parameters a and b.

### 7.11.3  Pareto Distribution Graphics

The Pareto distribution graphics functions are defined in the file pareto-graphics.ss in the random-distributions sub-collection of the science collection and are made available using the form:

```(require (planet "pareto-graphics.ss" ("williams" "science.plt")
"random-distributions"))
```

pareto-plot

 Function: `(pareto-plot a b)` Contract: `(-> real? real? any)`
This function returns a plot of the probability density and cumulative density of the Pareto distribution with parameters a and b. The plot is produced by the plot collection provided with PLT Scheme (PLoT Scheme).

Example: Plot of probability density and cumulative density of the Pareto distribution with parameters 1.0 and 1.0.

```(require (planet "pareto-graphics.ss" ("williams" "science.plt")
"random-distributions"))
(pareto-plot 1.0 1.0)
```

Figure 45 shows the resulting plot.

## 7.12  The T-Distribution

The t-distribution functions are defined in the t-distribution.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:

```(require (planet "t-distribution.ss" ("williams" "science.plt")
"random-distributions"))
```

### 7.12.1  Random Variates from the T-Distribution

random-t-distribution

 Function: ```(random-t-distribution s nu) (random-t-distribution nu)``` Contract: ```(case-> (-> random-source? real? real?)+ (-> real? real?))```
This function returns a random variate from the t-distribution with nu degrees of freedom using the random source s or (current-random-source) if s is not provided.

Example: Histogram of random variates from the t-distribution with 1.0 degrees of freedom.

```(require (planet "t-distribution.ss" ("williams" "science.plt")
"random-distributions"))
(require (planet "histogram-with-graphics.ss"
("williams" "science.plt")))

(let ((h (make-histogram-with-ranges-uniform 40 -6.0 6.0)))
(do ((i 0 (+ i 1)))
((= i 10000) (void))
(histogram-increment! h (random-t-distribution 1.0)))
(histogram-plot h "Histogram of t-Distribution"))
```

Figure 46 shows the resulting histogram.

### 7.12.2  T-Distribution Density Functions

t-distribution-pdf

 Function: `(t-distribution-pdf x nu)` Contract: `(-> real? real? (>=/c 0.0))`
This function computes the probability density, p(x), at x for the t-distribution with nu degrees of freedom.

t-distribution-cdf

 Function: `(t-distribution-cdf x nu)` Contract: `(-> real? real? (real-in 0.0 1.0))`
This function computes the cummulative density, d(x), at x for the t-distribution with nu degrees of freedom.

### 7.12.3  T-Distribution Graphics

The t-distribution graphics functions are defined in the file t-distribution-graphics .ss in the random-distributions sub-collection of the science collection and are made available using the form:

```(require (planet "t-distribution-graphics.ss"
("williams" "science.plt")
"random-distributions"))
```

t-distribution-plot

 Function: `(t-distribution-plot nu)` Contract: `(-> real? any)`
This function returns a plot of the probability density and cummulative density of the t-distribution with nu degrees of freedom. The plot is produced by the plot collection provided with PLT Scheme (PLoT Scheme).

Example: Plot of probability density and cummulative density of the t-distribution with 1.0 degrees of freedom.

```(require (planet "t-distribution-graphics.ss"
("williams" "science.plt")
"random-distributions"))
(t-distribution-plot 1.0)
```

Figure 47 shows the resulting plot.

## 7.13  The Triangular Distribution

The triangular distribution functions are defined in the triangular.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:

```(require (planet "triangular.ss" ("williams" "science.plt")
"random-distributions"))
```

### 7.13.1  Random Variates from the Triangular Distribution

random-triangular

 Function: ```(random-triangular s a b c) (random-triangular a b c)``` Contract: ```(case-> (->r ((s random-source?) (a real?) (b (>/c a)) (c (real-in a b))) real?) (->r ((a real?) (b (>/c a)) (c (real-in a b))) real?))```
This function returns a random variate from the triangular distribution with minimum value a, maximum value b, and most likely value c using the random source s or (current-random-source) if s is not provided.

Example: Histogram of random variates from the triangular distribution with minimum value 1.0, maximum value 4.0, and most likely value 2.0.

```(require (planet "triangular.ss" ("williams" "science.plt")
"random-distributions"))
(require (planet "histogram-with-graphics.ss"
("williams" "science.plt")))

(let ((h (make-histogram-with-ranges-uniform 40 1.0 4.0)))
(do ((i 0 (+ i 1)))
((= i 10000) (void))
(histogram-increment! h (random-triangular 1.0 4.0 2.0)))
(histogram-plot h "Histogram of Triangular Distribution"))
```

Figure 48 shows the resulting histogram.

### 7.13.2  Triangular Distribution Density Functions

triangular-pdf

 Function: `(triangular-pdf x a b c)` Contract: ```(->r ((x real?) (a real?) (b (>/c a)) (c (real-in a b))) (>=/c 0.0))```
This function computes the probability density, p(x), at x for the triangular distribution with minimum value a, maximum value b, and most likely value c.

triangular-cdf

 Function: `(triangular-cdf x a b c)` Contract: ```(->r ((x real?) (a real?) (b (>/c a)) (c (real-in a b))) (real-in 0.0 1.0))```
This function computes the cumulative density, d(x), at x for the triangular distribution with minimum value a, maximum value b, and most likely value c.

### 7.13.3  Triangular Distribution Graphics

The triangular distribution graphics functions are defined in the file triangular-graphics.ss in the random-distributions sub-collection of the science collection and are made available using the form:

```(require (planet "triangular-graphics.ss"
("williams" "science.plt")
"random-distributions"))
```

triangular-plot

 Function: `(triangular-plot a b c)` Contract: ```(->r ((a real?) (b (>/c a)) (c (real-in a b))) any)```
This function returns a plot of the probability density and cumulative density of the triangular distribution with minimum value a, maximum value b, and most likely value c. The plot is produced by the plot collection provided with PLT Scheme (PLoT Scheme).

Example: Plot of probability density of the triangular distribution with minimum value 1.0, maximum value 4.0, and most likely value 2.0.

```(require (planet "triangular-graphics.ss"
("williams" "science.plt")
"random-distributions"))
(triangular-plot 1.0 4.0 2.0)
```

Figure 49 shows the resulting plot.

## 7.14  The Bernoulli Distribution

The Bernoulli distribution functions are defined in the bernoulli.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:

```(require (planet "bernoulli.ss" ("williams" "science.plt")
"random-distributions"))
```

### 7.14.1  Random Variates from the Bernoulli Distribution

random-bernoulli

 Function: ```(random-bernoulli s p) (random-bernoulli p)``` Contract: ```(case-> (-> random-source? (real-in 0.0 1.0) (integer-in 0 1)) (-> (real-in 0.0 1.0) (integer-in 0 1)))```
This function returns a random variate from the Bernoulli distribution with probability p using the random source s or (current-random-source) if s is not provided.

Example: Histogram of random variates from the Bernoulli distribution with probability 0.6.

```(require (planet "bernoulli.ss" ("williams" "science.plt")
"random-distributions"))
(require (planet "discrete-histogram-with-graphics.ss"
("williams" "science.plt")))

(let ((h (make-discrete-histogram)))
(do ((i 0 (+ i 1)))
((= i 10000) (void))
(discrete-histogram-increment! h (random-bernoulli 0.6)))
(discrete-histogram-plot h "Histogram of Bernoulli Distribution"))
```

Figure 50 shows the resulting histogram.

### 7.14.2  Bernoulli Distribution Density Functions

bernoulli-pdf

 Function: `(bernoulli-pdf k p)` Contract: `(-> integer? (real-in 0.0 1.0) (>=/c 0.0))`
This function computes the probability density, p(k), at k for the Bernoulli distribution with probability p.

bernoulli-cdf

 Function: `(bernoulli-cdf k p)` Contract: `(-> integer? (real-in 0.0 1.0) (real-in 0.0 1.0))`
This function computes the cumulative density, d(k), at k for the Bernoulli distribution with probability p.

### 7.14.3  Bernoulli Distribution Graphics

The Bernoulli distribution graphics functions are defined in the file bernoulli-graphics.ss in the random-distributions sub-collection of the science collection and are made available using the form:

```(require (planet "bernoulli-graphics.ss"
("williams" "science.plt")
"random-distributions"))
```

bernoulli-plot

 Function: `(bernoulli-plot p)` Contract: `(-> (real-in 0.0 1.0) any)`
This function returns a plot of the probability density of the Bernoulli distribution with probability p. The plot is produced by the plot collection provided with PLT Scheme (PLoT Scheme).

Example: Plot of probability density of the Berboulli distribution with probability 0.6.

```(require (planet "bernoulli-graphics.ss"
("williams" "science.plt")
"random-distributions"))
(bernoulli-plot 0.6)
```

Figure 51 shows the resulting plot.

## 7.15  The Binomial Distribution

The binomial distribution functions are defined in the binomial.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:

```(require (planet "binomial.ss" ("williams" "science.plt")
"random-distributions"))
```

### 7.15.1  Random Variates from the Binomial Distribution

random-binomial

 Function: ```(random-binomial s p n) (random-binomial p n)``` Contract: ```(case-> (-> random-source? (real-in 0.0 1.0) natural-number? natural-number?) (-> (real-in 0.0 1.0) natural-number? natural-number?))```
This function returns a random variate from the binomial distribution with parameters p and n using the random source s or (current-random-source) if s is not provided.

Example: Histogram of random variates from the binomial distribution with parameters 0.5 and 20.

```(require (planet "binomial.ss" ("williams" "science.plt")
"random-distributions"))
(require (planet "discrete-histogram-with-graphics.ss"
("williams" "science.plt")))

(let ((h (make-discrete-histogram)))
(do ((i 0 (+ i 1)))
((= i 10000) (void))
(discrete-histogram-increment! h (random-binomial 0.5 20)))
(discrete-histogram-plot h "Histogram of Binomial Distribution"))
```

Figure 52 shows the resulting histogram.

### 7.15.2  Binomial Distribution Density Functions

binomial-pdf

 Function: `((binomial-pdf k p n)` Contract: `(-> integer? (real-in 0.0 1.0) natural-number? (>=/c 0.0))`
This function computes the probability density, p(k), at k for the binomial distribution with parameters p and n.

### 7.15.3  Binomial Distribution Graphics

The binomial distribution graphics functions are defined in the file binomial-graphics-.ss in the random-distributions sub-collection of the science collection and are made available using the form:

```(require (planet "binomial-graphics.ss" ("williams" "science.plt")
"random-distributions"))
```

binomial-plot

 Function: `(binomial-plot p n)` Contract: `(-> (real-in 0.0 1.0) natural-number? any)`
This function returns a plot of the probability density of the binomial distribution with parameters p and n. The plot is produced by the plot collection provided with PLT Scheme (PLoT Scheme).

Example: Plot of probability density of the binomial distribution with parameters 0.5 and 20.

```(require (planet "binomial-graphics.ss" ("williams" "science.plt")
"random-distributions"))
(binomial-plot 0.5 20)
```

Figure 53 shows the resulting plot.

## 7.16  The Geometric Distribution

The geometric distribution functions are defined in the geometric.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:

```(require (planet "geometric.ss" ("williams" "science.plt")
"random-distributions"))
```

### 7.16.1  Random Variates from the Geometric Distribution

random-geometric

 Function: ```(random-geometric s p) (random-geometric p)``` Contract: ```(case-> (-> random-source? (real-in 0.0 1.0) natural-number?) (-> (real-in 0.0 1.0) natural-number?))```
This function returns a random variate from the geometric distribution with probability p using the random source s or (current-random-source) if s is not provided.

Example: Histogram of random variates from the geometric distribution with probability 0.5.

```(require (planet "geometric.ss" ("williams" "science.plt")
"random-distributions"))
(require (planet "discrete-histogram-with-graphics.ss"
("williams" "science.plt")))

(let ((h (make-discrete-histogram)))
(do ((i 0 (+ i 1)))
((= i 10000) (void))
(discrete-histogram-increment! h (random-geometric 0.5)))
(discrete-histogram-plot h "Histogram of Geometric Distribution"))
```

Figure 54 shows the resulting histogram.

### 7.16.2  Geometric Distribution Density Functions

geometric-pdf

 Function: `(geometric-pdf k p)` Contract: `(-> integer? (real-in 0.0 1.0) (>=/c 0.0))`
This function computes the probability density, p(k), at k for the geometric distribution with probability p.

### 7.16.3  Geometric Distribution Graphics

The geometric distribution graphics functions are defined in the file geometric-graphics.ss in the random-distributions sub-collection of the science collection and are made available using the form:

```(require (planet "geometric-graphics.ss" ("williams" "science.plt")
"random-distributions"))
```

geometric-plot

 Function: `(geometric-plot p)` Contract: `(-> (real-in 0.0 1.0) any)`
This function returns a plot of the probability density of the geometric distribution with probability p. The plot is produced by the plot collection provided with PLT Scheme (PLoT Scheme).

Example: Plot of probability density of the geometric distribution with probability 0.5.

```(require (planet "geometric-graphics.ss" ("williams" "science.plt")
"random-distributions"))
(binomial-plot 0.5)
```

Figure 55 shows the resulting plot.

## 7.17  The Logarithmic Distribution

The logarithmic distribution functions are defined in the logarithmic.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:

```(require (planet "logarithmic.ss" ("williams" "science.plt")
"random-distributions"))
```

### 7.17.1  Random Variates from the Logarithmic Distribution

random-logarithmic

 Function: ```(random-logarithmic s p) (random-logarithmic p)``` Contract: ```(case-> (-> random-source? (real-in 0.0 1.0) natural-number?) (-> (real-in 0.0 1.0) natural-number?))```
This function returns a random variate from the logarithmic distribution with probabiliity p using the random source s or (current-random-source) if s is not provided.

Example: Histogram of random variates from the logarithmic distribution with probability 0.5.

```(require (planet "logarithmic.ss" ("williams" "science.plt")
"random-distributions"))
(require (planet "discrete-histogram-with-graphics.ss"
("williams" "science.plt")))

(let ((h (make-discrete-histogram)))
(do ((i 0 (+ i 1)))
((= i 10000) (void))
(discrete-histogram-increment! h (random-logarithmic 0.5)))
(discrete-histogram-plot h "Histogram of Logarithmic Distribution"))
```

Figure 56 shows the resulting histogram.

### 7.17.2  Logarithmic Distribution Density Functions

logarithmic-pdf

 Function: `(logarithmic-pdf k p)` Contract: `(-> integer? (real-in 0.0 1.0) (>=/c 0.0))`
This function computes the probability density, p(k), at k for the logarithmic distribution with probability p.

### 7.17.3  Logarithmic Distribution Graphics

The logarithmic distribution graphics functions are defined in the file logarithmic-graphics.ss in the random-distributions sub-collection of the science collection and are made available using the form:

```(require (planet "logarithmic-graphics.ss"
("williams" "science.plt")
"random-distributions"))
```

logarithmic-plot

 Function: `(logarithmic-plot p)` Contract: `(-> (real-in 0.0 1.0) any)`
This function returns a plot of the probability density of the logarithmic distribution with probability p. The plot is produced by the plot collection provided with PLT Scheme (PLoT Scheme).

Example: Plot of probability density of the logarithmic distribution with probability 0.5.

```(require (planet "logarithmic-graphics.ss"
("williams" "science.plt")
"random-distributions"))
(logarithmic-plot 0.5)
```

Figure 57 shows the resulting plot.

## 7.18  The Poisson Distribution

The Poisson distribution functions are defined in the poisson.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:

```(require (planet "poisson.ss" ("williams" "science.plt")
"random-distributions"))
```

### 7.18.1  Random Variates from the Poisson Distribution

random-poisson

 Function: ```(random-poisson s mu) (random-poisson mu)``` Contract: ```(case-> (-> random-source? real? natural-number?) (-> real? natural-number?))```
This function returns a random variate from the Poisson distribution with mean mu using the random source s or (current-random-source) if s is not provided.

Example: Histogram of random variates from the Poisson distribution with mean 10.0.

```(require (planet "poisson.ss" ("williams" "science.plt")
"random-distributions"))
(require (planet "discrete-histogram-with-graphics.ss"
("williams" "science.plt")))

(let ((h (make-discrete-histogram)))
(do ((i 0 (+ i 1)))
((= i 10000) (void))
(discrete-histogram-increment! h (random-poisson 10.0)))
(discrete-histogram-plot h "Histogram of Poisson Distribution"))
```

Figure 58 shows the resulting histogram.

### 7.18.2  Poisson Distribution Density Functions

poisson-pdf

 Function: `(poisson-pdf k mu)` Contract: `(-> integer? real? (>=/c 0.0))`
This function computes the probability density, p(k), at k for the Poisson distribution with mean mu.

### 7.18.3  Poisson Distribution Graphics

The Poisson distribution graphics functions are defined in the file poisson-graphics.ss in the random-distributions sub-collection of the science collection and are made available using the form:

```(require (planet "poisson-graphics.ss" ("williams" "science.plt")
"random-distributions"))
```

poisson-plot

 Function: `(poisson-plot mu)` Contract: `(-> (>/c 0.0) any)`
This function returns a plot of the probability density of the Poisson distribution with mean mu. The plot is produced by the plot collection provided with PLT Scheme (PLoT Scheme).

Example: Plot of probability density of the Poisson distribution with mean 10.0.

```(require (planet "poisson-graphics.ss" ("williams" "science.plt")
"random-distributions"))
(poisson-plot 10.0)
```

Figure 59 shows the resulting plot.

## 7.19  The General Discrete Distribution

The discrete distribution functions are defined in the discrete.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:

```(require (planet "discrete.ss" ("williams" "science.plt")
"random-distributions"))
```

discrete?

 Function: `(discrete? x)` Contract: `(-> any? boolean?)`
This function returns true, #t, if x is a discrete distribution and false, #f, otherwise.

### 7.19.1  Creating Discrete Distributions

make-discrete

 Function: `(make-discrete weights)` Contract: `(-> (vectorof real?) discrete?)`
This function returns a discrete distribution whose probability density is given by the specified weights. Note that the weights do not have to sum to one.

### 7.19.2  Random Variates from a Discrete Distribution

random-discrete

 Function: ```(random-discrete s d) (random-discrete d)``` Contract: ```(case-> (-> random-source? discrete?) (-> discrete?))```
This function returns a random variate from the discrete distribution d using the random source s or (current-random-source) if s is not provided.

Example: Histogram of random variates from a discrete distribution with weights #(.1 .4 .9 .8 .7 .6 .5 .4 .3 .2 .1).

```(require (planet "discrete.ss" ("williams" "science.plt")
"random-distributions"))
(require (planet "discrete-histogram-with-graphics.ss"
("williams" "science.plt")))

(let ((h (make-discrete-histogram))
(d (make-discrete #(.1 .4 .9 .8 .7 .6 .5 .4 .3 .2 .1))))
(do ((i 0 (+ i 1)))
((= i 10000) (void))
(discrete-histogram-increment! h (random-discrete d)))
(discrete-histogram-plot h "Histogram of Discrete Distribution"))
```

Figure 60 shows the resulting histogram.

### 7.19.3  Discrete Distribution Density Functions

discrete-pdf

 Function: `(discrete-pdf d k)` Contract: `(-> discrete? integer? (real-in 0.0 1.0))`
This function returns the probability density, p(k), at k for the discrete distribution d.

discrete-cdf

 Function: `(discrete-cdf d k)` Contract: `(-> discrete? integer? (real-in 0.0 1.0)`
This function returns the cumulative density, d(k), at k for the discrete distribution d.

### 7.19.4  General Discrete Distribution Graphics

The general discrete distribution graphics functions are defined in the file discrete-graphics.ss in the random-distributions sub-collection of the science collection and are made available using the form:

```(require (planet "discrete-graphics.ss" ("williams" "science.plt")
"random-distributions"))
```

discrete-plot

 Function: `(discrete-plot d)` Contract: `(-> discrete? any)`
This function returns a plot of the probability density of the general distribution d. The plot is produced by the plot collection provided with PLT Scheme (PLoT Scheme).

Example: Plot of probability density of the Poisson distribution with mean 10.0.

```(require (planet "discrete.ss" ("williams" "science.plt")
"random-distributions"))
(require (planet "discrete-graphics.ss" ("williams" "science.plt")
"random-distributions"))

(let ((d (make-discrete #(.1 .4 .9 .8 .7 .6 .5 .4 .3 .2 .1))))
(discrete-plot d))
```

Figure 61 shows the resulting plot.