Messages from list : cormas@cirad.fr

Choose a topic among the following archives :

Re: smallTalk programming a binomial function with mean = X?

New Message Reply Date view Thread view Subject view Author view

Subject: Re: smallTalk programming a binomial function with mean = X?
From: Serge Stinckwich (serge.stinckwich@gmail.com)
Date: Wed Mar 18 2009 - 16:31:42 CET

This is quick and dirty method in order to solve your problem.
You have to check it before use it.

1) Create a BinomialDistributionGenerator with 3 instances variables :
n, p and gen
2) Create the following methods :

BinomialDistributionGenerator >>initialize
        gen := Random new

BinomialDistributionGenerator >>n: anInteger
        n := anInteger

BinomialDistributionGenerator >>p: aProbability
        p := aProbability

BinomialDistributionGenerator>>next
        | x |
        x := 0.
        n
                timesRepeat: [gen next <= p
                                ifTrue: [x := x + 1]].
        ^ x

In order to use it in VisualWorks Smalltalk, you have to add i guess a
new class method (In Squeak, the initialize method is automatically
called) :

BinomialDistributionGenerator class>> new
^super new initialize

3) You can use it like this example :

b := BinomialDistributionGenerator new.
b p: 0.5; n:10.
b next.

On Wed, Mar 18, 2009 at 2:40 PM, Mehdi Saqalli <msqalli@yahoo.com> wrote:
> Hello to All!
> do someone can help us ?
> how to write a binomial function with a mean = X in SmallTAlk?
> thanks in advance
>
>
> ***************************************************
> Mehdi Saqalli
> LMTG - UMR 5563 UR 154 CNRS Université Paul-Sabatier IRD
> Observatoire Midi-Pyrénées - 14, avenue Edouard Belin - 31400 Toulouse,
> France
> fax : +33 (0)5 61 33 25 60 tel.: +33 (0)5 61 33 26 56 / +33 (0)6 16 03 80 37
> courriel: saqalli@lmtg.obs-mip.fr / msqalli@yahoo.com
> web : www.lmtg.obs-mip.fr / www.padniger.net /
> www.enge.ucl.ac.be/staff/past/saqalli.htm
>

-- 
Serge Stinckwich
UMI UMMISCO 209 (IRD/UPMC), Hanoi, Vietnam
Smalltalkers do: [:it | All with: Class, (And love: it)]
http://doesnotunderstand.org/

New Message Reply Date view Thread view Subject view Author view
 

Back to home