in reply to Perl : How to Create Unique String/Number?

Depending on what your needs are, a MD5 hash on time and user IP is probably best. The time-IP combination is not repeatable, and MD5 has an almost certain probability of creating a unique hash given a unique input.
  • Comment on Re: Perl : How to Create Unique String/Number?

Replies are listed 'Best First'.
Re^2: Perl : How to Create Unique String/Number?
by thor (Priest) on Jan 27, 2005 at 21:52 UTC
    The time-IP combination is not repeatable
    Time to what granularity? If you're talking to second-level granularity, I'll have to disagree. What about requests coming from behind a proxy? All of the internet traffic from my place of work seems to come from the same IP (and for all intents and purposes it does) regardless of the computer that's actually issuing the request. What happens when a lot of traffic is generated from one such place? If you think it can't happen, think again. Data::UUID is the way to go. Smarter people than you and I have thought about this problem and come up with that solution.

    thor

    Feel the white light, the light within
    Be your own disciple, fan the sparks of will
    For all of us waiting, your kingdom will come

      mmm, what characters should I not put because I want to generate an unique string that would be used for naming files?
        I'm not sure I understand the question. My original reply was with regards to the dangers of using time and IP address to generate a unique string. That having been said, I'll try my best to answer your question.

        There are no characters that are taboo when generating a unique string. The problem lies in generating a string that's guaranteed to be unique. Using things that shouldn't collide isn't good enough. Data::UUID guarantees no collision for the very foreseeable future. Use the solution that others have done a good job at implementing. You can have more fun in the spare time that you gain that way.

        thor

        Feel the white light, the light within
        Be your own disciple, fan the sparks of will
        For all of us waiting, your kingdom will come