Subject: Re: Random numbers ...
From: Pierre Bommel (bommel@cirad.fr)
Date: lun nov 26 2001 - 16:54:41 CET
Hello Damien,
Jourdain, Damien wrote:
> Dear all,
>
> I try to generate a serie of random numbers uniformely distributed between
> let say 0.7 and 0.1. I thought the routine to use would look something like
>
> | x y |
> x := OrderedCollection new.
> 1 to: 100 do: [ :p |
> y := Cormas randomFrom: 0.7 to: 1.
> x add: y.
> ].
>
> This, in fact generate a serie of numbers that are either 0.7 or 1 but
> nothing in between.
> What did I do wrong?
>
The class method "randomFrom:to:" return an integer (if the start value
is an integer), for example: Cormas randomFrom: 7 to: 10 can only return
4 values = 7, 8, 9 or 10.
In your case, if you want a collection of floats, between 0.7 and 1 with
a precision of 3, you can do that by this way :
| x y |
x := OrderedCollection new.
1 to: 100 do: [ :p |
y := (Cormas randomFrom: 700 to: 1000)/1000 asFloat.
x add: y].
Best regards,
Pierre
-- ************************************** * Pierre Bommel * * CIRAD TA 60/15 * * 73, rue Jean-François Breton * * 34398 Montpellier cedex 5 France * * Phone: +33 (0)4 67 59 38 53 * * Fax: +33 (0)4 67 59 38 27 * * http://cormas.cirad.fr * **************************************