This week's book giveaway is in the OCP forum.
We're giving away four copies of OCP Java SE 8 Programmer II Exam Study Guide and have Kathy Sierra, Bert Bates, & Elizabeth Robson on-line!
See this thread for details.
Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Random function  RSS feed

 
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I would like create a random function that generate a number between a min and a max value in J2ME. I couldn't do it.

OULD NADIF
 
Ould Nadif
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I resolved my problem:
Random Rand = new Random();
private int getRandomInt(int min, int max ){
int x = ((Rand.nextInt() >>> 1) % max);
return (x + min );
}



OULD NADIF
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!