• Post Reply Bookmark Topic Watch Topic
  • New Topic

Random integers  RSS feed

 
Sheng Ning
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Need to ask u guys a question
Is there any codes that can help me get two random number ?
thnks^^
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch! There's a method in the class java.util.Random called nextInt which can generate a uniform distribution for you. As an example, the code
(assuming an "import java.util.Random" or "import java.util.*" up top)

Could print out 0, 1, 2, 3, or 4. More information about the Random class in the official documentation.
On a seperate note, please review our naming policy and modify your display name to meet the guidelines. Thank you!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!