aspose file tools*
The moose likes Java in General and the fly likes how to genrate a random number inside the range Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to genrate a random number inside the range" Watch "how to genrate a random number inside the range" New topic
Author

how to genrate a random number inside the range

saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689
hi,

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
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
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
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
> 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
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://aspose.com/file-tools
 
subject: how to genrate a random number inside the range