# Will we have rand(m, n)?

**URL:** <https://www.ruby-forum.com/t/will-we-have-rand-m-n/114664>\
**Category:** Ruby\
**Created:** [September 17, 2007, 1:23pm UTC](https://www.ruby-forum.com/t/will-we-have-rand-m-n/114664 "2007-09-17T13:23:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![winterheat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@winterheat](https://www.ruby-forum.com/u/winterheat)\
**Post date:** [September 17, 2007, 1:23pm UTC](https://www.ruby-forum.com/t/will-we-have-rand-m-n/114664/1 "2007-09-17T13:23:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![winterheat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@winterheat](https://www.ruby-forum.com/u/winterheat)\
**Post date:** [September 25, 2007, 11:03pm UTC](https://www.ruby-forum.com/t/will-we-have-rand-m-n/114664/2 "2007-09-25T23:03:53Z")

</div>

On 9/15/07, kendear [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![winterheat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@winterheat](https://www.ruby-forum.com/u/winterheat)\
**Post date:** [September 25, 2007, 11:04pm UTC](https://www.ruby-forum.com/t/will-we-have-rand-m-n/114664/3 "2007-09-25T23:04:07Z")

</div>

On 9/15/07, Austin Z. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> readable than rand(m, n).  
> But would that draw discrete or continuous random numbers?

Hadley

---

<div class="post-metadata">

**Author:** ![winterheat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@winterheat](https://www.ruby-forum.com/u/winterheat)\
**Post date:** [September 25, 2007, 11:10pm UTC](https://www.ruby-forum.com/t/will-we-have-rand-m-n/114664/4 "2007-09-25T23:10:15Z")

</div>

On 15.09.2007 17:39, hadley wickham wrote:

> > 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
