This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Random number generation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Random number generation" Watch "Random number generation" New topic
Author

Random number generation

vijay shanker
Ranch Hand

Joined: Oct 26, 2007
Posts: 88
Hi all,

is there any way so i can generate a number always less then 255 when i am using


i need this value always be less then 255.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37958
    
  22
Never use new Random().nextAnything(); It is not as bad as it used to be under Java 1.4, but there is a risk of getting the same number sequence again.
Read the Random API documentation, and look carefully for what you quoted, namely nextInt(). You probably mean less than or equal to 255, so pass 256 not 255.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Random number generation
 
Similar Threads
GUI Problem
Loading an array with random integers.
colors in life!!!! :)
how to generate random numbers ? Random class always generate same number....
out of range error