Random 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 randomdistributions subcollection of the science collection. All of the modules in the randomdistributions subcollection can be made available using the form:
(require (planet "randomdistributions.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 "randomdistributionswithgraphics.ss" ("williams" "science.plt")))
The individual modules in the randomdistributions subcollection 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 randomdistributions subcollection of the sciencecollection and are made available using the form:
(require (planet "beta.ss" ("williams" "science.plt") "randomdistributions"))
7.1.1 Random Variates from the Beta Distribution
Function:
(randombeta s a b) (randombeta a b) 
Contract: (case> (> randomsource? real? real? (realin 0.0 1.0)) (> real? real? (realin 0.0 1.0))) 

Example: Histogram of random variates from the beta distribution with parameters 2.0 and 3.0.
(require (planet "beta.ss" ("williams" "science.plt") "randomdistributions")) (require (planet "histogramwithgraphics.ss" ("williams" "science.plt"))) (let ((h (makehistogramwithrangesuniform 40 0.0 1.0))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (histogramincrement! h (randombeta 2.0 3.0))) (histogramplot h "Histogram of Beta Distribution"))
Figure 20 shows the resulting histogram.

7.1.2 Beta Distribution Density Functions
Function:
(betapdf x a b) 
Contract: (> real? real? real? (>=/c 0.0)) 

Function:
(betacdf x a b) 
Contract: (> real? real? real? (realin 0.0 1.0)) 

7.1.3 Beta Distribution Graphics
The beta distribution graphics functions are defined in the file betagraphics.ss in the randomdistributions subcollection of the science collection and are made available using the form:
(require (planet "betagraphics.ss" ("williams" "science.plt") "randomdistributions"))
Function:
(betaplot a b) 
Contract: (> real? real? any) 

Example: Plot of probability density and cummulative density of the beta distribution with parameters 2.0 and 3.0.
(require (planet "betagraphics.ss" ("williams" "science.plt") "randomdistributions")) (betaplot 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 bivariategaussian.ss file in the randomdistributions subcollection of the sciencecollection and are made available using the form:
(require (planet "bivatiategaussian.ss" ("williams" "science.plt") "randomdistributions"))
7.2.1 Random Variates from the Bivariate Gaussian Distribution
Function:
(randombivariategaussian s sigmax sigmay rho) (randombivariategaussian sigmax sigmay rho) 
Contract: (case> (> randomsource? (>=/c 0.0) (>=/c 0.0) (realin 1.0 1.0) (values real? real?)) (> (>=/c 0.0) (>=/c 0.0) (realin 1.0 1.0) (values real? real?)) 

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 "bivariategaussian.ss" ("williams" "science.plt") "randomdistributions")) (require (planet "histogram2dwithgraphics.ss" ("williams" "science.plt"))) (let ((h (makehistogram2dwithrangesuniform 20 20 3.0 3.0 3.0 3.0))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (letvalues (((x y) (randombivariategaussian 1.0 1.0 0.0))) (histogram2dincrement! h x y))) (histogram2dplot h "Histogram of Bivariate Gaussian Distribution"))
Figure 22 shows the resulting 2D histogram.

7.2.2 Bivariate Gaussian Distribution Density Functions
Function:
(bivariategaussianpdf x y sigmax sigmay rho) 
Contract: (> real? real? (>=/c 0.0 (>=/c 0.0) (realin 1.0 0.0) real?) 

7.2.3 Bivariate Gaussian Distribution Graphics
The bivariate Gaussian distribution graphics functions are defined in the file bivariate gaussiangraphics.ss in the randomdistributions subcollection of the science collection and are made available using the form:
(require (planet "bivariategaussiangraphics.ss" ("williams" "science.plt") "randomdistributions"))
Function:
(bivariategaussianplot sigmax sigmay rho) 
Contract: (> (>=/c 0.0) (>=/c 0.0) (realin 1.0 1.0) any) 

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 "bivariategaussiangraphics.ss" ("williams" "science.plt") "randomdistributions")) (bivariategaussianplot 1.0 1.0 0.0)
Figure 23 shows the resulting plot.

7.3 The ChiSquared Distribution
The chisquared distribution functions are defined in the chisquared.ss file in the randomdistributions subcollection of the sciencecollection and are made available using the form:
(require (planet "chisquared.ss" ("williams" "science.plt") "randomdistributions"))
7.3.1 Random Variates from the ChiSquared Distribution
Function:
(randomchisquared s nu) (randomchisquared nu) 
Contract: (case> (> randomsource? real? (>=/c 0.0)) (> real? (>=/c 0.0))) 

Example: Histogram of random variates from the chi squared distribution with 3.0 degrees of freedom.
(require (planet "chisquared.ss" ("williams" "science.plt") "randomdistributions")) (require (planet "histogramwithgraphics.ss" ("williams" "science.plt"))) (let ((h (makehistogramwithrangesuniform 40 0.0 10.0))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (histogramincrement! h (randomchisquared 3.0))) (histogramplot h "Histogram of Chi Squared Distribution"))
Figure 24 shows the resulting histogram.

7.3.2 ChiSquared Distribution Density Functions
Function:
(chisquaredpdf x nu) 
Contract: (> real? real? (>=/c 0.0)) 

Function:
(chisquaredcdf x nu) 
Contract: (> real? real? (realin 0.0 1.0)) 

7.3.3 ChiSquared Distribution Graphics
The chi squared distribution graphics functions are defined in the file chisquaredgraphics.ss in the randomdistributions subcollection of the science collection and are made available using the form:
(require (planet "chisquaredgraphics.ss" ("williams" "science.plt") "randomdistributions"))
Function:
(chisquaredplot nu) 
Contract: (> real? any) 

Example: Plot of probability density and cummulative density of the chi squared distribution with 3.0 degrees of freedom.
(require (planet "chisquaredgraphics.ss" ("williams" "science.plt") "randomdistributions")) (chisquaredplot 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 randomdistributions subcollection of the sciencecollection and are made available using the form:
(require (planet "exponential.ss" ("williams" "science.plt") "randomdistributions"))
7.4.1 Random Variates from the Exponential Distribution
Function:
(randomexponential s mu) (randomexponential mu) 
Contract: (case> (> randomsource? (>/c 0.0) (>=/c 0.0)) (> (>/c 0.0) (>=/c 0.0))) 

Example: Histogram of random variates from the exponential distribution with mean 1.0.
(require (planet "exponential.ss" ("williams" "science.plt") "randomdistributions")) (require (planet "histogramwithgraphics.ss" ("williams" "science.plt"))) (let ((h (makehistogramwithrangesuniform 40 0.0 8.0))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (histogramincrement! h (randomexponential 1.0))) (histogramplot h "Histogram of Exponential Distribution"))
Figure 26 shows the resulting histogram.

7.4.2 Exponential Distribution Density Functions
Function:
(exponentialpdf x mu) 
Contract: (> real? real? (>=/c 0.0)) 

Function:
(exponentialcdf x mu) 
Contract: (> real? real? (realin 0.0 1.0)) 

7.4.3 Exponential Distribution Graphics
The exponential distribution graphics functions are defined in the file exponentialgraphics.ss in the randomdistributions subcollection of the science collection and are made available using the form:
(require (planet "exponentialgraphics.ss" ("williams" "science.plt") "randomdistributions"))
Function:
(exponentialplot mu) 
Contract: (> (>=/c 0.0) any) 

Example: Plot of probability density and cummulative density of the exponential distribution with mean 3.0.
(require (planet "exponentialgraphics.ss" ("williams" "science.plt") "randomdistributions")) (exponentialplot 3.0)
Figure 27 shows the resulting plot.

7.5 The FDistribution
The Fdistribution functions are defined in the fdistribution.ss file in the randomdistributions subcollection of the sciencecollection and are made available using the form:
(require (planet "fdistribution.ss" ("williams" "science.plt") "randomdistributions"))
7.5.1 Random Variates from the FDistribution
Function:
(randomfdistribution s nu1 nu2) (randomfdistribution nu1 nu2) 
Contract: (case> (> randomsource? real? real? (>=/c 0.0)) (> real? real? (>=/c 0.0))) 

Example: Histogram of random variates from the Fdistribution with 2.0 and 3.0 degrees of freedom.
(require (planet "fdistribution.ss" ("williams" "science.plt") "randomdistributions")) (require (planet "histogramwithgraphics.ss" ("williams" "science.plt"))) (let ((h (makehistogramwithrangesuniform 40 0.0 10.0))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (histogramincrement! h (randomfdistribution 2.0 3.0))) (histogramplot h "Histogram of FDistribution"))
Figure 28 shows the resulting histogram.

7.5.2 FDistribution Density Functions
Function:
(fdistributionpdf x nu1 nu2) 
Contract: (> real? real? real? (>=/c 0.0)) 

Function:
(fdistributionpdf x nu1 nu2) 
Contract: (> real? real? real? (realin 0.0 1.0)) 

7.5.3 FDistribution Graphics
The exponential distribution graphics functions are defined in the file fdistributiongraphics.ss in the randomdistributions subcollection of the science collection and are made available using the form:
(require (planet "fdistributiongraphics.ss" ("williams" "science.plt") "randomdistributions"))
Function:
(fdistributionplot nu1 nu2) 
Contract: (> (>=/c 0.0) any) 

Example: Plot of probability density of the Fdistribution distribution with 2.0 and 3.0 degrees of freedom.
(require (planet "fdistributiongraphics.ss" ("williams" "science.plt" 2 0) "randomdistributions")) (fdistributionplot 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 randomdistributions subcollection of the sciencecollection and are made available using the form:
(require (planet "flat.ss" ("williams" "science.plt") "randomdistributions"))
7.6.1 Random Variates from the Flat Distribution
Function:
(randomflat s a b) (randomflat a b) 
Contract: (case> (>r ((s randomsource?) (a real?) (b (>/c a)) real?) (>r ((a real?) (b (>/c a)) real?)) 

Example: Histogram of random variates from the flat (uniform) distribution from 1.0 to 4.0.
(require (planet "flat.ss" ("williams" "science.plt") "randomdistributions")) (require (planet "histogramwithgraphics.ss" ("williams" "science.plt"))) (let ((h (makehistogramwithrangesuniform 40 1.0 4.0))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (histogramincrement! h (randomflat 1.0 4.0))) (histogramplot h "Histogram of Flat (Uniform) Distribution"))
Figure 30 shows the resulting histogram.

7.6.2 Flat Distribution Density Functions
Function:
(flatpdf x a b) 
Contract: (>r ((x real?) (a real?) (b (>/c a))) (>=/c 0.0)) 

Function:
(flatcdf x a b) 
Contract: (>r ((x real?) (a real?) (b (>/c a))) (realin 0.0 1.0)) 

7.6.3 Flat Distribution Graphics
The flat (uniform) distribution graphics functions are defined in the file flatgraphics.ss in the randomdistributions subcollection of the science collection and are made available using the form:
(require (planet "flatgraphics.ss" ("williams" "science.plt") "randomdistributions"))
Function:
(flatplot a b) 
Contract: (>r ((a real?) (b (>/c a))) any) 

Example: Plot of probability density and cumulative density of the flat (uniform) distribution from 1.0 to 4.0.
(require (planet "flatgraphics.ss" ("williams" "science.plt") "randomdistributions")) (flatplot 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 randomdistributions subcollection of the sciencecollection and are made available using the form:
(require (planet "gamma.ss" ("williams" "science.plt") "randomdistributions"))
7.7.1 Random Variates from the Gamma Distribution
Function:
(randomgamma s a b)(randomgamma a b) 
Contract: (case> (> randomsource? (>/c 0.0) real? (>=/c 0.0)) (> (>/c 0.0 real? (>=/c 0.0))) 

Example: Histogram of random variates from the gamma distribution with parameters 3.0 and 3.0.
(require (planet "gamma.ss" ("williams" "science.plt") "randomdistributions")) (require (planet "histogramwithgraphics.ss" ("williams" "science.plt"))) (let ((h (makehistogramwithrangesuniform 40 0.0 24.0))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (histogramincrement! h (randomgamma 3.0 3.0))) (histogramplot h "Histogram of Gamma Distribution"))
Figure 32 shows the resulting histogram.

7.7.2 Gamma Distribution Density Functions
Function:
(gammapdf x a b) 
Contract: (> real? (>/c 0.0) real? (>=/c 0.0)) 

Function:
(gammacdf x a b) 
Contract: (> real? (>/c 0.0) real? (realin 0.0 1.0)) 

7.7.3 Gamma Distribution Graphics
The gamma distribution graphics functions are defined in the file gammagraphics.ss in the randomdistributions subcollection of the science collection and are made available using the form:
(require (planet "gammagraphics.ss" ("williams" "science.plt") "randomdistributions"))
Function:
(gammaplot a b) 
Contract: (> (>/c 0.0) real?) 

Example: Plot of probability density and cummulative density of the gamma distribution with parameters 3.0 and 3.0.
(require (planet "gammagraphics.ss" ("williams" "science.plt") "randomdistributions")) (gammaplot 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 randomdistributions subcollection of the sciencecollection and are made available using the form:
(require (planet "gaussian.ss" ("williams" "science.plt") "randomdistributions"))
7.8.1 Random Variates from the Gaussian Distribution
Function:
(randomgaussian s mu sigma) (randomgaussian mu sigma) 
Contract: (case> (> randomsource? real? (>=/c 0.0) real?) (> real? (>=/c 0.0) real?)) 

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") "randomdistributions")) (require (planet "histogramwithgraphics.ss" ("williams" "science.plt"))) (let ((h (makehistogramwithrangesuniform 40 4.0 16.0))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (histogramincrement! h (randomgaussian 10.0 2.0))) (histogramplot h "Histogram of Gaussian Distribution"))
Figure 34 shows the resulting histogram.

Function:
(randomunitgaussian s) (randomunitgaussian) 
Contract: (case> (> randomsource? real?) (> real?)) 

Example: Histogram of random variates from the unit Gaussian (normal) distribution.
(require (planet "gaussian.ss" ("williams" "science.plt") "randomdistributions")) (require (planet "histogramwithgraphics.ss" ("williams" "science.plt"))) (let ((h (makehistogramwithrangesuniform 40 3.0 3.0))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (histogramincrement! h (randomunitgaussian))) (histogramplot h "Histogram of Unit Gaussian Distribution"))
Figure 35 shows the resulting histogram.

Function:
(randomgaussianratiomethod s mu sigma) (randomgaussianratiomethod mu sigma) 
Contract: (case> (> randomsource? real? (>=/c 0.0) real?) (> real? (>=/c 0.0) real?)) 

randomunitgaussianratiomethod
Function:
(randomunitgaussianratiomethod s) (randomunitgaussianratiomethod) 
Contract: (case> (> randomsource? real?) (> real?)) 

7.8.2 Gaussian Distribution Density Functions
Function:
(gaussianpdf x mu sigma) 
Contract: (> real? real? (>/c 0.0) (>=/c 0.0)) 

Function:
(gaussiancdf x mu sigma) 
Contract: (> real? real? (>/c 0.0) (realin 0.0 1.0)) 

Function:
(unitgaussianpdf x) 
Contract: (> real? (>=/c 0.0)) 

Function:
(unitgaussiancdf x) 
Contract: (> real? (realin 0.0 1.0)) 

7.8.3 Gaussian Distribution Graphics
The Gaussian distribution graphics functions are defined in the file gaussiangraphics.ss in the randomdistributions subcollection of the science collection and are made available using the form:
(require (planet "gaussiangraphics.ss" ("williams" "science.plt") "randomdistributions"))
Function:
(gaussianplot mu sigma) 
Contract: (> real? (>/c 0.0) any) 

Example: Plot of probability density and cumulative density of the Gaussian (normal) distribution with mean 10.0 and standard deviation 2.0.
(require (planet "gaussiangraphics.ss" ("williams" "science.plt") "randomdistributions")) (gaussianplot 10.0 2.0)
Figure 36 shows the resulting plot.

Function:
(unitgaussianplot) 
Contract: (> any) 

Example: Plot of probability density and cumulative density of the Gaussian (normal) distribution with mean 0.0 and standard deviation 1.0.
(require (planet "gaussiangraphics.ss" ("williams" "science.plt") "randomdistributions")) (unitgaussianplot)
Figure 37 shows the resulting plot.

7.9 The Gaussian Tail Distribution
The Gaussian tail distribution functions are defined in the gaussiantail.ss file in the randomdistributions subcollection of the sciencecollection and are made available using the form:
(require (planet "gaussiantail.ss" ("williams" "science.plt") "randomdistributions"))
7.9.1 Random Variates from the Gaussian Tail Distribution
Function:
(randomgaussiantail s a mu sigma) (randomgaussiantail a mu sigma 
Contract: (case> (> randomsource? real? real? (>/c 0.0) real?) (> real? real? (>/c 0.0) real?)) 

Function:
(randomunitgaussiantail s a) (randomunitgaussiantail a 
Contract: (case> (> randomsource? (>/c 0.0) (>/c 0.0)) (> (>/c 0.0))) 

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 "gaussiantail.ss" ("williams" "science.plt") "randomdistributions")) (require (planet "histogramwithgraphics.ss" ("williams" "science.plt"))) (let ((h (makehistogramwithrangesuniform 40 16.0 22.0))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (histogramincrement! h (randomgaussiantail 16.0 10.0 2.0))) (histogramplot 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 "gaussiantail.ss" ("williams" "science.plt") "randomdistributions")) (require (planet "histogramwithgraphics.ss" ("williams" "science.plt"))) (let ((h (makehistogramwithrangesuniform 40 3.0 6.0))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (histogramincrement! h (randomunitgaussiantail 3.0))) (histogramplot h "Histogram of Unit Gaussian Tail Distribution"))
Figure 39 shows the resulting histogram.

7.9.2 Gaussian Tail Distribution Density Functions
Function:
(gaussiantailpdf x a mu sigma) 
Contract: (> real? real? real? (>/c 0.0) (>=/c 0.0)) 

Function:
(unitgaussiantailpdf x a) 
Contract: (> real? (>=/c 0.0) (>=/c 0.0)) 

7.9.3 Gaussian Tail Distribution Graphics
The Gaussian tail distribution graphics functions are defined in the file gaussian tailgraphics.ss in the randomdistributions subcollection of the science collection and are made available using the form:
(require (planet "gaussiantailgraphics.ss" ("williams" "science.plt") "randomdistributions"))
Function:
(gaussiantailplot a mu sigma) 
Contract: (> real? real? (>/c 0.0) any) 

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 "gaussiantailgraphics.ss" ("williams" "science.plt" 2 0) "randomdistributions")) (gaussiantailplot 16.0 10.0 2.0)
Figure 40 shows the resulting plot.

Function:
(unitgaussiantailplot a) 
Contract: (> (>=/c 0.0) any) 

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 "gaussiantailgraphics.ss" ("williams" "science.plt") "randomdistributions")) (unitgaussiantailplot 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 randomdistributions subcollection of the sciencecollection and are made available using the form:
(require (planet "lognormal.ss" ("williams" "science.plt") "randomdistributions"))
7.10.1 Random Variates from the Log Normal Distribution
Function:
(randomlognormal s mu sigma) (randomlognormal mu sigma) 
Contract: (case> (> randomsource? real? (>=/c 0.0) real?) (> real? real?)) 

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") "randomdistributions")) (require (planet "histogramwithgraphics.ss" ("williams" "science.plt"))) (let ((h (makehistogramwithrangesuniform 40 0.0 6.0))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (histogramincrement! h (randomlognormal 0.0 1.0))) (histogramplot h "Histogram of Log Normal Distribution"))
Figure 42 shows the resulting histogram.

7.10.2 Log Normal Distribution Density Functions
Function:
(lognormalpdf x mu sigma) 
Contract: (> real? real? (>/c 0.0) (>=/c 0.0)) 

Function:
(lognormalcdf x mu sigma) 
Contract: (> real? real? (>/c 0.0) (realin 0.0 1.0)) 

7.10.3 Log Normal Distribution Graphics
The log normal distribution graphics functions are defined in the file lognormalgraphics.ss in the randomdistributions subcollection of the science collection and are made available using the form:
(require (planet "lognormalgraphics.ss" ("williams" "science.plt") "randomdistributions"))
Function:
(lognormalplot mu sigma) 
Contract: (> real? (>/c 0.0) any) 

Example: Plot of probability density and cumulative density of the log normal distribution with mean 0.0 and standard deviation 1.0.
(require (planet "lognormalgraphics.ss" ("williams" "science.plt") "randomdistributions")) (lognormalplot 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 randomdistributions subcollection of the sciencecollection and are made available using the form:
(require (planet "pareto.ss" ("williams" "science.plt") "randomdistributions"))
7.11.1 Random Variates from the Pareto Distribution
Function:
(randompareto s a b) (randompareto a b) 
Contract: (case> (> randomsource? real? real? real?) (> real? real? real?)) 

Example: Histogram of random variates from the Pareto distribution with parameters 1.0 and 1.0.
(require (planet "pareto.ss" ("williams" "science.plt") "randomdistributions")) (require (planet "histogramwithgraphics.ss" ("williams" "science.plt"))) (let ((h (makehistogramwithrangesuniform 40 1.0 21.0))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (histogramincrement! h (randompareto 1.0 1.0))) (histogramplot h "Histogram of Pareto Distribution"))
Figure 44 shows the resulting histogram.

7.11.2 Pareto Distribution Density Functions
Function:
(paretopdf x a b) 
Contract: (> real? real? real? (>=/c 0.0)) 

Function:
(paretocdf x a b) 
Contract: (> real? real? real? (realin 0.0 1.0)) 

7.11.3 Pareto Distribution Graphics
The Pareto distribution graphics functions are defined in the file paretographics.ss in the randomdistributions subcollection of the science collection and are made available using the form:
(require (planet "paretographics.ss" ("williams" "science.plt") "randomdistributions"))
Function:
(paretoplot a b) 
Contract: (> real? real? any) 

Example: Plot of probability density and cumulative density of the Pareto distribution with parameters 1.0 and 1.0.
(require (planet "paretographics.ss" ("williams" "science.plt") "randomdistributions")) (paretoplot 1.0 1.0)
Figure 45 shows the resulting plot.

7.12 The TDistribution
The tdistribution functions are defined in the tdistribution.ss file in the randomdistributions subcollection of the sciencecollection and are made available using the form:
(require (planet "tdistribution.ss" ("williams" "science.plt") "randomdistributions"))
7.12.1 Random Variates from the TDistribution
Function:
(randomtdistribution s nu) (randomtdistribution nu) 
Contract: (case> (> randomsource? real? real?)+ (> real? real?)) 

Example: Histogram of random variates from the tdistribution with 1.0 degrees of freedom.
(require (planet "tdistribution.ss" ("williams" "science.plt") "randomdistributions")) (require (planet "histogramwithgraphics.ss" ("williams" "science.plt"))) (let ((h (makehistogramwithrangesuniform 40 6.0 6.0))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (histogramincrement! h (randomtdistribution 1.0))) (histogramplot h "Histogram of tDistribution"))
Figure 46 shows the resulting histogram.

7.12.2 TDistribution Density Functions
Function:
(tdistributionpdf x nu) 
Contract: (> real? real? (>=/c 0.0)) 

Function:
(tdistributioncdf x nu) 
Contract: (> real? real? (realin 0.0 1.0)) 

7.12.3 TDistribution Graphics
The tdistribution graphics functions are defined in the file tdistributiongraphics .ss in the randomdistributions subcollection of the science collection and are made available using the form:
(require (planet "tdistributiongraphics.ss" ("williams" "science.plt") "randomdistributions"))
Function:
(tdistributionplot nu) 
Contract: (> real? any) 

Example: Plot of probability density and cummulative density of the tdistribution with 1.0 degrees of freedom.
(require (planet "tdistributiongraphics.ss" ("williams" "science.plt") "randomdistributions")) (tdistributionplot 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 randomdistributions subcollection of the sciencecollection and are made available using the form:
(require (planet "triangular.ss" ("williams" "science.plt") "randomdistributions"))
7.13.1 Random Variates from the Triangular Distribution
Function:
(randomtriangular s a b c) (randomtriangular a b c) 
Contract: (case> (>r ((s randomsource?) (a real?) (b (>/c a)) (c (realin a b))) real?) (>r ((a real?) (b (>/c a)) (c (realin a b))) real?)) 

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") "randomdistributions")) (require (planet "histogramwithgraphics.ss" ("williams" "science.plt"))) (let ((h (makehistogramwithrangesuniform 40 1.0 4.0))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (histogramincrement! h (randomtriangular 1.0 4.0 2.0))) (histogramplot h "Histogram of Triangular Distribution"))
Figure 48 shows the resulting histogram.

7.13.2 Triangular Distribution Density Functions
Function:
(triangularpdf x a b c) 
Contract: (>r ((x real?) (a real?) (b (>/c a)) (c (realin a b))) (>=/c 0.0)) 

Function:
(triangularcdf x a b c) 
Contract: (>r ((x real?) (a real?) (b (>/c a)) (c (realin a b))) (realin 0.0 1.0)) 

7.13.3 Triangular Distribution Graphics
The triangular distribution graphics functions are defined in the file triangulargraphics.ss in the randomdistributions subcollection of the science collection and are made available using the form:
(require (planet "triangulargraphics.ss" ("williams" "science.plt") "randomdistributions"))
Function:
(triangularplot a b c) 
Contract: (>r ((a real?) (b (>/c a)) (c (realin a b))) any) 

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 "triangulargraphics.ss" ("williams" "science.plt") "randomdistributions")) (triangularplot 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 randomdistributions subcollection of the sciencecollection and are made available using the form:
(require (planet "bernoulli.ss" ("williams" "science.plt") "randomdistributions"))
7.14.1 Random Variates from the Bernoulli Distribution
Function:
(randombernoulli s p) (randombernoulli p) 
Contract: (case> (> randomsource? (realin 0.0 1.0) (integerin 0 1)) (> (realin 0.0 1.0) (integerin 0 1))) 

Example: Histogram of random variates from the Bernoulli distribution with probability 0.6.
(require (planet "bernoulli.ss" ("williams" "science.plt") "randomdistributions")) (require (planet "discretehistogramwithgraphics.ss" ("williams" "science.plt"))) (let ((h (makediscretehistogram))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (discretehistogramincrement! h (randombernoulli 0.6))) (discretehistogramplot h "Histogram of Bernoulli Distribution"))
Figure 50 shows the resulting histogram.

7.14.2 Bernoulli Distribution Density Functions
Function:
(bernoullipdf k p) 
Contract: (> integer? (realin 0.0 1.0) (>=/c 0.0)) 

Function:
(bernoullicdf k p) 
Contract: (> integer? (realin 0.0 1.0) (realin 0.0 1.0)) 

7.14.3 Bernoulli Distribution Graphics
The Bernoulli distribution graphics functions are defined in the file bernoulligraphics.ss in the randomdistributions subcollection of the science collection and are made available using the form:
(require (planet "bernoulligraphics.ss" ("williams" "science.plt") "randomdistributions"))
Function:
(bernoulliplot p) 
Contract: (> (realin 0.0 1.0) any) 

Example: Plot of probability density of the Berboulli distribution with probability 0.6.
(require (planet "bernoulligraphics.ss" ("williams" "science.plt") "randomdistributions")) (bernoulliplot 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 randomdistributions subcollection of the sciencecollection and are made available using the form:
(require (planet "binomial.ss" ("williams" "science.plt") "randomdistributions"))
7.15.1 Random Variates from the Binomial Distribution
Function:
(randombinomial s p n) (randombinomial p n) 
Contract: (case> (> randomsource? (realin 0.0 1.0) naturalnumber? naturalnumber?) (> (realin 0.0 1.0) naturalnumber? naturalnumber?)) 

Example: Histogram of random variates from the binomial distribution with parameters 0.5 and 20.
(require (planet "binomial.ss" ("williams" "science.plt") "randomdistributions")) (require (planet "discretehistogramwithgraphics.ss" ("williams" "science.plt"))) (let ((h (makediscretehistogram))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (discretehistogramincrement! h (randombinomial 0.5 20))) (discretehistogramplot h "Histogram of Binomial Distribution"))
Figure 52 shows the resulting histogram.

7.15.2 Binomial Distribution Density Functions
Function:
((binomialpdf k p n) 
Contract: (> integer? (realin 0.0 1.0) naturalnumber? (>=/c 0.0)) 

7.15.3 Binomial Distribution Graphics
The binomial distribution graphics functions are defined in the file binomialgraphics.ss in the randomdistributions subcollection of the science collection and are made available using the form:
(require (planet "binomialgraphics.ss" ("williams" "science.plt") "randomdistributions"))
Function:
(binomialplot p n) 
Contract: (> (realin 0.0 1.0) naturalnumber? any) 

Example: Plot of probability density of the binomial distribution with parameters 0.5 and 20.
(require (planet "binomialgraphics.ss" ("williams" "science.plt") "randomdistributions")) (binomialplot 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 randomdistributions subcollection of the sciencecollection and are made available using the form:
(require (planet "geometric.ss" ("williams" "science.plt") "randomdistributions"))
7.16.1 Random Variates from the Geometric Distribution
Function:
(randomgeometric s p) (randomgeometric p) 
Contract: (case> (> randomsource? (realin 0.0 1.0) naturalnumber?) (> (realin 0.0 1.0) naturalnumber?)) 

Example: Histogram of random variates from the geometric distribution with probability 0.5.
(require (planet "geometric.ss" ("williams" "science.plt") "randomdistributions")) (require (planet "discretehistogramwithgraphics.ss" ("williams" "science.plt"))) (let ((h (makediscretehistogram))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (discretehistogramincrement! h (randomgeometric 0.5))) (discretehistogramplot h "Histogram of Geometric Distribution"))
Figure 54 shows the resulting histogram.

7.16.2 Geometric Distribution Density Functions
Function:
(geometricpdf k p) 
Contract: (> integer? (realin 0.0 1.0) (>=/c 0.0)) 

7.16.3 Geometric Distribution Graphics
The geometric distribution graphics functions are defined in the file geometricgraphics.ss in the randomdistributions subcollection of the science collection and are made available using the form:
(require (planet "geometricgraphics.ss" ("williams" "science.plt") "randomdistributions"))
Function:
(geometricplot p) 
Contract: (> (realin 0.0 1.0) any) 

Example: Plot of probability density of the geometric distribution with probability 0.5.
(require (planet "geometricgraphics.ss" ("williams" "science.plt") "randomdistributions")) (binomialplot 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 randomdistributions subcollection of the sciencecollection and are made available using the form:
(require (planet "logarithmic.ss" ("williams" "science.plt") "randomdistributions"))
7.17.1 Random Variates from the Logarithmic Distribution
Function:
(randomlogarithmic s p) (randomlogarithmic p) 
Contract: (case> (> randomsource? (realin 0.0 1.0) naturalnumber?) (> (realin 0.0 1.0) naturalnumber?)) 

Example: Histogram of random variates from the logarithmic distribution with probability 0.5.
(require (planet "logarithmic.ss" ("williams" "science.plt") "randomdistributions")) (require (planet "discretehistogramwithgraphics.ss" ("williams" "science.plt"))) (let ((h (makediscretehistogram))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (discretehistogramincrement! h (randomlogarithmic 0.5))) (discretehistogramplot h "Histogram of Logarithmic Distribution"))
Figure 56 shows the resulting histogram.

7.17.2 Logarithmic Distribution Density Functions
Function:
(logarithmicpdf k p) 
Contract: (> integer? (realin 0.0 1.0) (>=/c 0.0)) 

7.17.3 Logarithmic Distribution Graphics
The logarithmic distribution graphics functions are defined in the file logarithmicgraphics.ss in the randomdistributions subcollection of the science collection and are made available using the form:
(require (planet "logarithmicgraphics.ss" ("williams" "science.plt") "randomdistributions"))
Function:
(logarithmicplot p) 
Contract: (> (realin 0.0 1.0) any) 

Example: Plot of probability density of the logarithmic distribution with probability 0.5.
(require (planet "logarithmicgraphics.ss" ("williams" "science.plt") "randomdistributions")) (logarithmicplot 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 randomdistributions subcollection of the sciencecollection and are made available using the form:
(require (planet "poisson.ss" ("williams" "science.plt") "randomdistributions"))
7.18.1 Random Variates from the Poisson Distribution
Function:
(randompoisson s mu) (randompoisson mu) 
Contract: (case> (> randomsource? real? naturalnumber?) (> real? naturalnumber?)) 

Example: Histogram of random variates from the Poisson distribution with mean 10.0.
(require (planet "poisson.ss" ("williams" "science.plt") "randomdistributions")) (require (planet "discretehistogramwithgraphics.ss" ("williams" "science.plt"))) (let ((h (makediscretehistogram))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (discretehistogramincrement! h (randompoisson 10.0))) (discretehistogramplot h "Histogram of Poisson Distribution"))
Figure 58 shows the resulting histogram.

7.18.2 Poisson Distribution Density Functions
Function:
(poissonpdf k mu) 
Contract: (> integer? real? (>=/c 0.0)) 

7.18.3 Poisson Distribution Graphics
The Poisson distribution graphics functions are defined in the file poissongraphics.ss in the randomdistributions subcollection of the science collection and are made available using the form:
(require (planet "poissongraphics.ss" ("williams" "science.plt") "randomdistributions"))
Function:
(poissonplot mu) 
Contract: (> (>/c 0.0) any) 

Example: Plot of probability density of the Poisson distribution with mean 10.0.
(require (planet "poissongraphics.ss" ("williams" "science.plt") "randomdistributions")) (poissonplot 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 randomdistributions subcollection of the sciencecollection and are made available using the form:
(require (planet "discrete.ss" ("williams" "science.plt") "randomdistributions"))
Function:
(discrete? x) 
Contract: (> any? boolean?) 

7.19.1 Creating Discrete Distributions
Function:
(makediscrete weights) 
Contract: (> (vectorof real?) discrete?) 

7.19.2 Random Variates from a Discrete Distribution
Function:
(randomdiscrete s d) (randomdiscrete d) 
Contract: (case> (> randomsource? discrete?) (> discrete?)) 

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") "randomdistributions")) (require (planet "discretehistogramwithgraphics.ss" ("williams" "science.plt"))) (let ((h (makediscretehistogram)) (d (makediscrete #(.1 .4 .9 .8 .7 .6 .5 .4 .3 .2 .1)))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (discretehistogramincrement! h (randomdiscrete d))) (discretehistogramplot h "Histogram of Discrete Distribution"))
Figure 60 shows the resulting histogram.

7.19.3 Discrete Distribution Density Functions
Function:
(discretepdf d k) 
Contract: (> discrete? integer? (realin 0.0 1.0)) 

Function:
(discretecdf d k) 
Contract: (> discrete? integer? (realin 0.0 1.0) 

7.19.4 General Discrete Distribution Graphics
The general discrete distribution graphics functions are defined in the file discretegraphics.ss in the randomdistributions subcollection of the science collection and are made available using the form:
(require (planet "discretegraphics.ss" ("williams" "science.plt") "randomdistributions"))
Function:
(discreteplot d) 
Contract: (> discrete? any) 

Example: Plot of probability density of the Poisson distribution with mean 10.0.
(require (planet "discrete.ss" ("williams" "science.plt") "randomdistributions")) (require (planet "discretegraphics.ss" ("williams" "science.plt") "randomdistributions")) (let ((d (makediscrete #(.1 .4 .9 .8 .7 .6 .5 .4 .3 .2 .1)))) (discreteplot d))
Figure 61 shows the resulting plot.
