• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Random function

 
Ould Nadif
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