I want to generate a random number for a specific range like in between 20 to 70 no.s
cinux
A = HARDWORK B = LUCK/FATE If C=(A+B) then C=SUCCESSFUL IN LIFE else C=FAILURE IN LIFE
SCJP 1.4
Sri Ram
Ranch Hand
Joined: Oct 03, 2005
Posts: 118
posted
0
Sai, I had a same kind a requirement in one of my modules. I used the Random class for this. check this code
num will have the random number between 30 - 40
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
posted
0
Notice that there is even a method nextInt(int n) on the Random class.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Sri Ram
Ranch Hand
Joined: Oct 03, 2005
Posts: 118
posted
0
Originally posted by Ilja Preuss: Notice that there is even a method nextInt(int n) on the Random class.
But doesnt this method generate random number between 0 and specified value.
regards Sriram
Jeff Albertson
Ranch Hand
Joined: Sep 16, 2005
Posts: 1780
posted
0
> But doesnt this method generate random number between 0 and specified value.
So add the lower bound. Is this really an advanced question?
There is no emoticon for what I am feeling!
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
posted
0
Originally posted by Jeff Albrechtsen: Is this really an advanced question?
No, it isn't. Moving to intermediate...
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: how to genrate a random number inside the range