Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print out a random number between a range? [duplicate]

I've the following but it doesn't work:

<%= (5..30).sample %> 
like image 913
user1049097 Avatar asked Nov 18 '11 00:11

user1049097


People also ask

How do I generate a random number between ranges in Excel?

Select the cell in which you want to get the random numbers. In the active cell, enter =RANDBETWEEN(1,100). Hold the Control key and Press Enter.


2 Answers

Give this a shot.

<%= [*5..30].sample %> 

...or...

<%= rand(5..30) %> 
like image 88
alex Avatar answered Sep 30 '22 12:09

alex


This would generate a random number in that range:

5 + rand(25) 

Simply add the min to the rand(max-min).

like image 33
mduvall Avatar answered Sep 30 '22 10:09

mduvall