Hello,
Thanks for reading this.
I am very new to Ruby and have been learning using a tutorial at http://pine.fm/LearnToProgram/
by Chris (thanks Chris)
After searching fairly thoroughly in forums and tutorials I found no
answer to my problem.
I have come to a point where i need to generate a random number within a
range.
I have learnt that rand(100) produces random numbers from 0 to 99 but i
need to know how to set a minimum for the random number.
Just add the minimum value to whatever number you generate. For example, if
you wanted to generate a random number between 0 and 99 with a minimum value
of 20:
rand(80) + 20
···
On 1/6/07, Ruby N00bie <ralphallan@gmail.com> wrote:
I have learnt that rand(100) produces random numbers from 0 to 99 but i
need to know how to set a minimum for the random number.
Generate a random number between 0 and 50, and add 50 to the result.
m.
···
Ruby N00bie <ralphallan@gmail.com> wrote:
Hello,
Thanks for reading this.
I am very new to Ruby and have been learning using a tutorial at Learn to Program, by Chris Pine
by Chris (thanks Chris)
After searching fairly thoroughly in forums and tutorials I found no
answer to my problem.
I have come to a point where i need to generate a random number within a
range.
I have learnt that rand(100) produces random numbers from 0 to 99 but i
need to know how to set a minimum for the random number.
Hello,
Thanks for reading this.
I am very new to Ruby and have been learning using a tutorial at Learn to Program, by Chris Pine
by Chris (thanks Chris)
After searching fairly thoroughly in forums and tutorials I found no
answer to my problem.
I have come to a point where i need to generate a random number within a
range.
I have learnt that rand(100) produces random numbers from 0 to 99 but i
need to know how to set a minimum for the random number.
You have to do this yourself, say you want a random number between 42 and a
than you have to write
42+rand(a+1-42) # BTW it would be legal to write a - 41
It would be nice an exercise to define your own method to do this
HTH
Robert
···
On 1/6/07, Ruby N00bie <ralphallan@gmail.com> wrote:
Hello,
Thanks for reading this.
I am very new to Ruby and have been learning using a tutorial at Learn to Program, by Chris Pine
by Chris (thanks Chris)
After searching fairly thoroughly in forums and tutorials I found no
answer to my problem.
I have come to a point where i need to generate a random number within a
range.
I have learnt that rand(100) produces random numbers from 0 to 99 but i
need to know how to set a minimum for the random number.
--
"The real romance is out ahead and yet to come. The computer revolution
hasn't started yet. Don't be misled by the enormous flow of money into bad
defacto standards for unsophisticated buyers using poor adaptations of
incomplete ideas."