PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > Re: will we have rand(m, n)?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Re: will we have rand(m, n)?

Réponse
 
LinkBack Outils de la discussion
Vieux 15/09/2007, 14h51   #1
Austin Ziegler
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: will we have rand(m, n)?

On 9/15/07, kendear <summercoolness@gmail.com> wrote:
> given the ease of using Ruby, I wonder whether we will have rand(m, n) in
> the future...
>
> right now, we need to use rand(range) + start
>
> and it can cause a bug that can otherwise be avoided if we have rand(m, n)
> for the clarity.


Why not instead suggest rand(m..n)? That would, I think, be more
readable than rand(m, n).

-austin
--
Austin Ziegler * halostatue@gmail.com * http://www.halostatue.ca/
* austin@halostatue.ca * http://www.halostatue.ca/feed/
* austin@zieglers.ca

  Réponse avec citation
Vieux 15/09/2007, 16h39   #2
hadley wickham
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: will we have rand(m, n)?

On 9/15/07, Austin Ziegler <halostatue@gmail.com> wrote:
> On 9/15/07, kendear <summercoolness@gmail.com> wrote:
> > given the ease of using Ruby, I wonder whether we will have rand(m, n) in
> > the future...
> >
> > right now, we need to use rand(range) + start
> >
> > and it can cause a bug that can otherwise be avoided if we have rand(m, n)
> > for the clarity.

>
> Why not instead suggest rand(m..n)? That would, I think, be more
> readable than rand(m, n).


But would that draw discrete or continuous random numbers?

Hadley

  Réponse avec citation
Vieux 15/09/2007, 16h45   #3
Robert Klemme
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: will we have rand(m, n)?

On 15.09.2007 17:39, hadley wickham wrote:
> On 9/15/07, Austin Ziegler <halostatue@gmail.com> wrote:
>> On 9/15/07, kendear <summercoolness@gmail.com> wrote:
>>> given the ease of using Ruby, I wonder whether we will have rand(m, n) in
>>> the future...
>>>
>>> right now, we need to use rand(range) + start
>>>
>>> and it can cause a bug that can otherwise be avoided if we have rand(m, n)
>>> for the clarity.

>> Why not instead suggest rand(m..n)? That would, I think, be more
>> readable than rand(m, n).

>
> But would that draw discrete or continuous random numbers?


That question actually applies to both variants. :-)

The rule could probably be, if at least one of the two numbers is non
int (i.e. float) then a "continuous" range is used. Alternatively we
can define another function that does this ("frand" or "randf").

Btw, currently if you use a float as single parameter you still get
integers back as far as I can see.

Kind regards

robert
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 15h51.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10605 seconds with 11 queries