Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

creating unique ID's using input digits

  • 09-05-2008 12:43pm
    #1
    Registered Users, Registered Users 2 Posts: 4,359 ✭✭✭


    hi,

    I have 10 digits to work with, whats the best way of creating a unique Id from a 10 digit input? concatenate , pad, byte swap then convert to ascii characters?

    any ideas


Comments

  • Registered Users, Registered Users 2 Posts: 981 ✭✭✭fasty


    This sounds a bit homeworkey :P What you're looking for is a hash function and for 10 digit values (like social security numbers) there's quite a few ways.

    http://en.wikipedia.org/wiki/Hash_function
    Wikipedia wrote:
    Hashing uniformly distributed data
    If the inputs are bounded-length strings (such as telephone numbers, car license plates, invoice numbers, etc.), and each input may independently occur with uniform probability, then a hash function needs only map roughly the same number of inputs to each hash value. For instance, suppose that each input is an integer z in the range 0 to N−1, and the output must be an integer h in the range 0 to n−1, where N is much larger than n. Then the hash function could be h = z mod n (the remainder of z divided by n), or h = (z × n) ÷ N (the value z scaled down by n/N and truncated to an integer) --- or many other formulas.

    Or have a look at this: http://books.google.ie/books?id=L7NOABDqaMcC&pg=PA143&lpg=PA143&dq=social+security+number+hash+function&source=web&ots=arGshYJmns&sig=lPaeuS4pAZXACcr_bbbrGXC-SHg&hl=en


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    Yes just do a hash though technically there is a chance you could end up with the same hash value from two different inputs but the chances of that are very small - small enough not to worry about.

    If php just use md5()


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    I'd recommend Md5 for .Net too


  • Registered Users, Registered Users 2 Posts: 4,359 ✭✭✭jon1981


    its not homework, its just something im working on, finished college years ago :D

    i need an algorithim that will always generate the same 8 digit unique id from an input of 10-16 characters long. was just looking for some sources on this kinda thing. also id like to do it in a way thats not bound to a language i.e not using functions specific to php, perl, java...etc


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    I'm sure theres a way of adapting a Guid generating algorithim to what you want.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,426 ✭✭✭ressem


    It's a phone number?

    Is the priority the uniqueness of the derived number, inability to reverse the procedure, or CPU time (on a simple microprocessor or the like)?

    You say that the output definitely has to be 8 digits? By this do you mean 0-9, base64, 7 bit ascii or UTF-8 or a 64/128 bit number?

    In theory using MD5 or SHA1, then truncating to fit a certain size will give you some uniqueness but it would be better to use more than 32 - 64 bits.


Advertisement