This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Random number generation

 
vijay shanker
Ranch Hand
Posts: 88
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47216
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic