Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

random numbers gen

 
j srinivas
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well iam unable to create random numbers betn 1-100,without repetetion.
iam declaring an array to store all random numbers.
then generate an array number and compare it with array elements
but it is not getting done
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a particular reason you're not using java.util.Random.nextInt ? It's not easy to program a good RNG on your own.
 
Alberto Caraz
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By without repetition you mean you want to randomly permute a sequence of numbers and then show them one by one? If that's the case I would recommend creating a list of numbers from 1 to n and then calling Collections.shuffle on it. Then your "ith" random number will be the "ith" element of this sequence.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic