Some random musings

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Some random musings

SergeStinckwich
Hi Pharoers,

some random musings about Random numbers :-)

In the context of the CORMAS project:
http://cormas.cirad.fr/indexeng.htm
I would like to propose an API for manipulating random numbers
to users who are not developers but modelers of complex systems.

In CORMAS, people need to generate a lot of random numbers for simulation for exemple. For example, you can do:

Cormas randomFloatFrom: -4.1 to: 2.5

​At the moment, there is no Pharo API to generate with a one-liner a random float number between two values for example.

You can do this for integers: 10 atRandom to generate an integer between 1 to 10.

There is atRandom defined on Interval, so can you say :
(2.3 to: 4.5) atRandom
but it will not generate a random float numbers between 2.3 and 4.5

but numbers like: 2.3, 3.3 or 4.3.
because Interval are considered as a Collection.

​Any comments about that ?
How we can enhance the situation ?​
Any interest to introduce a method to produce random float numbers in an interval in Pharo ?

​Thank you​
--
Serge Stinckwich
UMI UMMISCO 209 (SU/IRD/UY1)
"Programs must be written for people to read, and only incidentally for machines to execute."
http://www.doesnotunderstand.org/
Reply | Threaded
Open this post in threaded view
|

Re: Some random musings

Sven Van Caekenberghe-2
I think

  Float randomFrom: -4.1 to: 2.5

or

  Float randomBetween: -4.1 and: 2.5

would be the most descriptive and compliant to your signature ;-)

An interval does not necessarily contain Floats.
Going to the class side of Float makes sense because you create a new instance.

> On 16 Apr 2018, at 11:51, Serge Stinckwich <[hidden email]> wrote:
>
> Hi Pharoers,
>
> some random musings about Random numbers :-)
>
> In the context of the CORMAS project:
> http://cormas.cirad.fr/indexeng.htm
> I would like to propose an API for manipulating random numbers
> to users who are not developers but modelers of complex systems.
>
> In CORMAS, people need to generate a lot of random numbers for simulation for exemple. For example, you can do:
>
> Cormas randomFloatFrom: -4.1 to: 2.5
>
> ​At the moment, there is no Pharo API to generate with a one-liner a random float number between two values for example.
>
> You can do this for integers: 10 atRandom to generate an integer between 1 to 10.
>
> There is atRandom defined on Interval, so can you say :
> (2.3 to: 4.5) atRandom
> but it will not generate a random float numbers between 2.3 and 4.5
>
> but numbers like: 2.3, 3.3 or 4.3.
> because Interval are considered as a Collection.
>
> ​Any comments about that ?
> How we can enhance the situation ?​
> Any interest to introduce a method to produce random float numbers in an interval in Pharo ?
>
> ​Thank you​
> --
> Serge Stinckwich
> UMI UMMISCO 209 (SU/IRD/UY1)
> "Programs must be written for people to read, and only incidentally for machines to execute."
> http://www.doesnotunderstand.org/


Reply | Threaded
Open this post in threaded view
|

Re: Some random musings

Julien
Hello,

Then this should be added to Integer class as well no?

So the API is uniform.

Because, if I am not wrong, for now if you want to generate an integer that could be negative you have to use an Interval

(-10 to: 10) atRandom

Since

10 atRandom

In fact generates a Natural number and not an Integer… :-)

Julien

---
Julien Delplanque
Doctorant à l’Université de Lille 1
Bâtiment B 40, Avenue Halley 59650 Villeneuve d'Ascq
Numéro de téléphone: +333 59 35 86 40

Le 16 avr. 2018 à 12:51, Sven Van Caekenberghe <[hidden email]> a écrit :

I think

 Float randomFrom: -4.1 to: 2.5

or

 Float randomBetween: -4.1 and: 2.5

would be the most descriptive and compliant to your signature ;-)

An interval does not necessarily contain Floats.
Going to the class side of Float makes sense because you create a new instance.

On 16 Apr 2018, at 11:51, Serge Stinckwich <[hidden email]> wrote:

Hi Pharoers,

some random musings about Random numbers :-)

In the context of the CORMAS project:
http://cormas.cirad.fr/indexeng.htm
I would like to propose an API for manipulating random numbers
to users who are not developers but modelers of complex systems.

In CORMAS, people need to generate a lot of random numbers for simulation for exemple. For example, you can do:

Cormas randomFloatFrom: -4.1 to: 2.5

​At the moment, there is no Pharo API to generate with a one-liner a random float number between two values for example.

You can do this for integers: 10 atRandom to generate an integer between 1 to 10.

There is atRandom defined on Interval, so can you say :
(2.3 to: 4.5) atRandom
but it will not generate a random float numbers between 2.3 and 4.5

but numbers like: 2.3, 3.3 or 4.3.
because Interval are considered as a Collection.

​Any comments about that ?
How we can enhance the situation ?​
Any interest to introduce a method to produce random float numbers in an interval in Pharo ?

​Thank you​
--
Serge Stinckwich
UMI UMMISCO 209 (SU/IRD/UY1)
"Programs must be written for people to read, and only incidentally for machines to execute."
http://www.doesnotunderstand.org/



Reply | Threaded
Open this post in threaded view
|

Re: Some random musings

jtuchel
In reply to this post by Sven Van Caekenberghe-2
Sven, Serge,

Especially in the case of Floats, I think between:and: is *not* a good name.
As always, the question is if between:and: is exclusive or inclusive of
the border values... So I think the better name is from:to:. I think
this name indicates it includes the border values.

Joachim




Am 16.04.18 um 12:51 schrieb Sven Van Caekenberghe:

> I think
>
>    Float randomFrom: -4.1 to: 2.5
>
> or
>
>    Float randomBetween: -4.1 and: 2.5
>
> would be the most descriptive and compliant to your signature ;-)
>
> An interval does not necessarily contain Floats.
> Going to the class side of Float makes sense because you create a new instance.
>
>> On 16 Apr 2018, at 11:51, Serge Stinckwich <[hidden email]> wrote:
>>
>> Hi Pharoers,
>>
>> some random musings about Random numbers :-)
>>
>> In the context of the CORMAS project:
>> http://cormas.cirad.fr/indexeng.htm
>> I would like to propose an API for manipulating random numbers
>> to users who are not developers but modelers of complex systems.
>>
>> In CORMAS, people need to generate a lot of random numbers for simulation for exemple. For example, you can do:
>>
>> Cormas randomFloatFrom: -4.1 to: 2.5
>>
>> ​At the moment, there is no Pharo API to generate with a one-liner a random float number between two values for example.
>>
>> You can do this for integers: 10 atRandom to generate an integer between 1 to 10.
>>
>> There is atRandom defined on Interval, so can you say :
>> (2.3 to: 4.5) atRandom
>> but it will not generate a random float numbers between 2.3 and 4.5
>>
>> but numbers like: 2.3, 3.3 or 4.3.
>> because Interval are considered as a Collection.
>>
>> ​Any comments about that ?
>> How we can enhance the situation ?​
>> Any interest to introduce a method to produce random float numbers in an interval in Pharo ?
>>
>> ​Thank you​
>> --
>> Serge Stinckwich
>> UMI UMMISCO 209 (SU/IRD/UY1)
>> "Programs must be written for people to read, and only incidentally for machines to execute."
>> http://www.doesnotunderstand.org/
>
>

--
-----------------------------------------------------------------------
Objektfabrik Joachim Tuchel          mailto:[hidden email]
Fliederweg 1                         http://www.objektfabrik.de
D-71640 Ludwigsburg                  http://joachimtuchel.wordpress.com
Telefon: +49 7141 56 10 86 0         Fax: +49 7141 56 10 86 1


Reply | Threaded
Open this post in threaded view
|

Re: Some random musings

Sven Van Caekenberghe-2
In reply to this post by Julien


> On 16 Apr 2018, at 12:57, Julien <[hidden email]> wrote:
>
> Hello,
>
> Then this should be added to Integer class as well no?
>
> So the API is uniform.

Probably yes.

> Because, if I am not wrong, for now if you want to generate an integer that could be negative you have to use an Interval
>
> (-10 to: 10) atRandom
>
> Since
>
> 10 atRandom
>
> In fact generates a Natural number and not an Integer… :-)

Indeed

>
> Julien
>
> ---
> Julien Delplanque
> Doctorant à l’Université de Lille 1
> http://juliendelplanque.be/phd.html
> Equipe Rmod, Inria
> Bâtiment B 40, Avenue Halley 59650 Villeneuve d'Ascq
> Numéro de téléphone: +333 59 35 86 40
>
>> Le 16 avr. 2018 à 12:51, Sven Van Caekenberghe <[hidden email]> a écrit :
>>
>> I think
>>
>>  Float randomFrom: -4.1 to: 2.5
>>
>> or
>>
>>  Float randomBetween: -4.1 and: 2.5
>>
>> would be the most descriptive and compliant to your signature ;-)
>>
>> An interval does not necessarily contain Floats.
>> Going to the class side of Float makes sense because you create a new instance.
>>
>>> On 16 Apr 2018, at 11:51, Serge Stinckwich <[hidden email]> wrote:
>>>
>>> Hi Pharoers,
>>>
>>> some random musings about Random numbers :-)
>>>
>>> In the context of the CORMAS project:
>>> http://cormas.cirad.fr/indexeng.htm
>>> I would like to propose an API for manipulating random numbers
>>> to users who are not developers but modelers of complex systems.
>>>
>>> In CORMAS, people need to generate a lot of random numbers for simulation for exemple. For example, you can do:
>>>
>>> Cormas randomFloatFrom: -4.1 to: 2.5
>>>
>>> ​At the moment, there is no Pharo API to generate with a one-liner a random float number between two values for example.
>>>
>>> You can do this for integers: 10 atRandom to generate an integer between 1 to 10.
>>>
>>> There is atRandom defined on Interval, so can you say :
>>> (2.3 to: 4.5) atRandom
>>> but it will not generate a random float numbers between 2.3 and 4.5
>>>
>>> but numbers like: 2.3, 3.3 or 4.3.
>>> because Interval are considered as a Collection.
>>>
>>> ​Any comments about that ?
>>> How we can enhance the situation ?​
>>> Any interest to introduce a method to produce random float numbers in an interval in Pharo ?
>>>
>>> ​Thank you​
>>> --
>>> Serge Stinckwich
>>> UMI UMMISCO 209 (SU/IRD/UY1)
>>> "Programs must be written for people to read, and only incidentally for machines to execute."
>>> http://www.doesnotunderstand.org/
>>
>>
>


Reply | Threaded
Open this post in threaded view
|

Re: Some random musings

Sven Van Caekenberghe-2
In reply to this post by jtuchel
#between:and: is a well known test selector, which is inclusive on both ends.

> On 16 Apr 2018, at 12:59, [hidden email] wrote:
>
> Sven, Serge,
>
> Especially in the case of Floats, I think between:and: is *not* a good name.
> As always, the question is if between:and: is exclusive or inclusive of the border values... So I think the better name is from:to:. I think this name indicates it includes the border values.
>
> Joachim
>
>
>
>
> Am 16.04.18 um 12:51 schrieb Sven Van Caekenberghe:
>> I think
>>
>>   Float randomFrom: -4.1 to: 2.5
>>
>> or
>>
>>   Float randomBetween: -4.1 and: 2.5
>>
>> would be the most descriptive and compliant to your signature ;-)
>>
>> An interval does not necessarily contain Floats.
>> Going to the class side of Float makes sense because you create a new instance.
>>
>>> On 16 Apr 2018, at 11:51, Serge Stinckwich <[hidden email]> wrote:
>>>
>>> Hi Pharoers,
>>>
>>> some random musings about Random numbers :-)
>>>
>>> In the context of the CORMAS project:
>>> http://cormas.cirad.fr/indexeng.htm
>>> I would like to propose an API for manipulating random numbers
>>> to users who are not developers but modelers of complex systems.
>>>
>>> In CORMAS, people need to generate a lot of random numbers for simulation for exemple. For example, you can do:
>>>
>>> Cormas randomFloatFrom: -4.1 to: 2.5
>>>
>>> ​At the moment, there is no Pharo API to generate with a one-liner a random float number between two values for example.
>>>
>>> You can do this for integers: 10 atRandom to generate an integer between 1 to 10.
>>>
>>> There is atRandom defined on Interval, so can you say :
>>> (2.3 to: 4.5) atRandom
>>> but it will not generate a random float numbers between 2.3 and 4.5
>>>
>>> but numbers like: 2.3, 3.3 or 4.3.
>>> because Interval are considered as a Collection.
>>>
>>> ​Any comments about that ?
>>> How we can enhance the situation ?​
>>> Any interest to introduce a method to produce random float numbers in an interval in Pharo ?
>>>
>>> ​Thank you​
>>> --
>>> Serge Stinckwich
>>> UMI UMMISCO 209 (SU/IRD/UY1)
>>> "Programs must be written for people to read, and only incidentally for machines to execute."
>>> http://www.doesnotunderstand.org/
>>
>>
>
> --
> -----------------------------------------------------------------------
> Objektfabrik Joachim Tuchel          mailto:[hidden email]
> Fliederweg 1                         http://www.objektfabrik.de
> D-71640 Ludwigsburg                  http://joachimtuchel.wordpress.com
> Telefon: +49 7141 56 10 86 0         Fax: +49 7141 56 10 86 1
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Some random musings

Pharo Smalltalk Users mailing list
In reply to this post by SergeStinckwich
"Any interest to introduce a method to produce random float numbers in an interval in Pharo ?"

Yes, that would definitely be useful !!!!  And it would not only be useful for Float but for all numbers.  Would save us from the usual "#truncated and +1" trick we always have to write!!


-----------------
Benoît St-Jean
Yahoo! Messenger: bstjean
Twitter: @BenLeChialeux
Pinterest: benoitstjean
Instagram: Chef_Benito
IRC: lamneth
Blogue: endormitoire.wordpress.com
"A standpoint is an intellectual horizon of radius zero".  (A. Einstein)
Reply | Threaded
Open this post in threaded view
|

Re: Some random musings

Pharo Smalltalk Users mailing list
In reply to this post by Sven Van Caekenberghe-2
"Float randomBetween: -4.1 and: 2.5
would be the most descriptive and compliant to your signature ;-)"

I also prefer #randomBetween:and: .

"Going to the class side of Float makes sense because you create a new instance."

But I'm not so sure about putting this on the class side.

In fact, right now #atRandom is on the instance side and it's been that way since the beginning.  It would be akward to have one method of generating random numbers on the class side and all others on the instance side.  And moving everything on the class side would break tons of code and legacy code.  Besides, random numbers have always been seen and/or dealt with as streams : the intent was to get "the next one" in the stream, not create "a new instance"



-----------------
Benoît St-Jean
Yahoo! Messenger: bstjean
Twitter: @BenLeChialeux
Pinterest: benoitstjean
Instagram: Chef_Benito
IRC: lamneth
Blogue: endormitoire.wordpress.com
"A standpoint is an intellectual horizon of radius zero".  (A. Einstein)