[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Set minimum for random number generator

OrganicFreeStyle

6/11/2006 3:54:00 PM

Hi all. I'm programming a model of economic relationships in both
python and ruby near simultaneously, and as with most simulations, I
need to generate a random number within a specific range. I'm a python
man, and in python you can call random.randint(min, max) to achieve
this. Rand allows you to set the max, but what about the min? Is there
a similar method to Python's randint() in Ruby? Alternative random
number generators that have this ability? Thanks.

3 Answers

ZeD

6/11/2006 4:15:00 PM

0

OrganicFreeStyle wrote:

> Hi all. I'm programming a model of economic relationships in both
> python and ruby near simultaneously, and as with most simulations, I
> need to generate a random number within a specific range. I'm a python
> man, and in python you can call random.randint(min, max) to achieve
> this. Rand allows you to set the max, but what about the min? Is there
> a similar method to Python's randint() in Ruby? Alternative random
> number generators that have this ability? Thanks.

from a non-ruby developer :)

min + rand (max-min)

--
Under construction

OrganicFreeStyle

6/11/2006 4:30:00 PM

0


ZeD wrote:
> OrganicFreeStyle wrote:
>
> > Hi all. I'm programming a model of economic relationships in both
> > python and ruby near simultaneously, and as with most simulations, I
> > need to generate a random number within a specific range. I'm a python
> > man, and in python you can call random.randint(min, max) to achieve
> > this. Rand allows you to set the max, but what about the min? Is there
> > a similar method to Python's randint() in Ruby? Alternative random
> > number generators that have this ability? Thanks.
>
> from a non-ruby developer :)
>
> min + rand (max-min)
>
> --
> Under construction

Brilliant. Such elegance! Thank you ZeD, much appreciated.

Serendipity

6/27/2006 6:15:00 AM

0

>
> min + rand (max-min)
>


Just what I was looking for...thanks!