VisezTrance

  • August 4, 2010 12:31 AM

    Generating a unique identifier

    By Daniel
    Generating a unique string value is a fairly common idiom. I always thought the fastest/easiest way to do so was by merging a timestamp with a random value. Not really unique, but fairly close nevertheless.
    Yet, there's better way by using UUID which provides a more reliable unique identifier. Most languages either have it build in or there's a library available.

    For example, in php I could use the build in uniqid() function:

    print uniqid();
    > "4c5896b421e54"

    or in ruby with the help of the uuid gem:

    UUID.generate
    > "73f93750-817b-012d-5ea3-00242165bf55"
  • Monthly Archives

    • October 2013 (2)
    • May 2012 (1)
    • October 2011 (1)
    • September 2011 (2)
    • March 2011 (3)
    • February 2011 (1)
    • January 2011 (1)
    • September 2010 (1)
    • August 2010 (1)
    • June 2010 (1)
    • April 2010 (1)
    • December 2009 (1)
    • October 2009 (1)
    • September 2009 (1)
    • August 2009 (1)
    • July 2009 (2)
    • April 2009 (2)
    • February 2009 (1)
    • January 2009 (2)
    • December 2008 (1)
    • October 2008 (1)
  • Pages

    • About / Contact

2008, © Daniel Mircea