Generating never repeated sequence



  • I need to find an algorithm of generation that never recurs. The sequence may consist of numerals and letters (please include unreadable symbols). It's about the same thing as GUID's generosity in COM-objects. If anyone knows popular algorithms/libraries, I'm asking you to share the advice.



  • The whole question lies in the degree of certainty of the uniqueness of the code. If this is not very principled (for example, the probability of a repeat code of about 10 to minus 6-7) is that it is perfectly normal to take the current time + an accidental symbol and a hash key to this value. In the pseudos, I would have written:

    return hash(System.currentTimeMillis() & random());
    

    If there's a need for iron concrete confidence, you need a special generator. In Java, there's a convenient package. http://docs.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/atomic/package-summary.html




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2