s c h e m a t i c s : c o o k b o o k

/ Cookbook.NumberRandomNumberDistributions

This Web


WebHome 
WebChanges 
TOC (with recipes)
NewRecipe 
WebTopicList 
WebStatistics 

Other Webs


Chicken
Cookbook
Erlang
Know
Main
Plugins
Sandbox
Scm
TWiki  

Schematics


Schematics Home
Sourceforge Page
SchemeWiki.org
Original Cookbook
RSS

Scheme Links


Schemers.org
Scheme FAQ
R5RS
SRFIs
Scheme Cross Reference
PLT Scheme SISC
Scheme48 SCM
MIT Scheme scsh
JScheme Kawa
Chicken Guile
Bigloo Tiny
Gambit LispMe
GaucheChez

Lambda the Ultimate
TWiki.org

Generation of Random Numbers of a Given Distribution

Problem

Generation of random numbers following a certain probability distribution.

Solution

Use the random library from PLaneT.

> (require (planet "random.scm" ("schematics" "random.plt" 1 1)))

; Let X be a stochastic variable with a normal distribution of mean 2 and variance 1.
> (define X (lambda () (random-normal 2 1)))
> (X)
2.738691213443679
> (X)
1.5611005495389303

; Let Y be a stochastic variable with binomal distribution the number-of-trials 10 and
; the probability paramter 1/2.
> (define Y (lambda () (random-binomial 10 1/2)))
> (Y)
6

The library contains among others the functions supporting discrete distribtions

and the following continous distributions

See the Documentation for more elaborate explanations.

Discussion


Comments about this recipe

Contributors

-- JensAxelSoegaard - 25 Aug 2004

CookbookForm
TopicType: Recipe
ParentTopic: NumberRecipes
TopicOrder: 999

 
 
Copyright © 2004 by the contributing authors. All material on the Schematics Cookbook web site is the property of the contributing authors.
The copyright for certain compilations of material taken from this website is held by the SchematicsEditorsGroup - see ContributorAgreement & LGPL.
Other than such compilations, this material can be redistributed and/or modified under the terms of the GNU Lesser General Public License (LGPL), version 2.1, as published by the Free Software Foundation.
Ideas, requests, problems regarding Schematics Cookbook? Send feedback.
/ You are Main.guest