• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Generation of Random Number

 
Ranch Hand
Posts: 257
Hibernate Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Can any one help me in generating random number sequence for real time application.

with following constraint,
the routine should not access the current time stamp or db time stamp.

I have tried with util.Random and math.random() they are not generated unique random numbers, after a period of time , say after every 100 or 150 numbers , they are generating again same set of numbers.

Help required.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


unique random numbers


There is nothing in either of those classes that guarentees uniqueness. If this is a single JVM application, you might look at the UID class
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The difficulty is in the fact that you want unique numbers.

You could do this by first making a list of all possible numbers, and then call Collections.shuffle(...) on the list to put them in random order. Then you just iterate the list to get random numbers. This solution might not be practical if the range of all possible numbers is large, or when you need a lot of random numbers.
 
Time is the best teacher, but unfortunately, it kills all of its students - Robin Williams. tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic