realbasic-nug
[Top] [All Lists]

Re: Advice on Generating Unique Digits From String

To: realbasic-nug at lists dot realsoftware dot com
Subject: Re: Advice on Generating Unique Digits From String
From: "Craig A. Finseth" <fin at finseth dot com>
Date: Tue, 30 Oct 2007 14:23:04 -0500 (CDT)
Cc: realbasic-nug at lists dot realsoftware dot com
Delivered-to: listarchive at realsoftware dot com
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <72FE594F-FD4C-4427-8F5D-6C48208DC1F7 at kimballlarsen dot com> <4B6C0786-BD99-41DB-B542-D2CE0B8F7D8B at inspiringapps dot com>
   >    m = NewMemoryBlock(17)
   >    m.CString(0) = md5(s)
   >    return m.UInt16Value(0)

   Hmm, I wouldn't necessarily trust this, since (as you pointed out)  
   you're taking only the first two bytes of a 16-byte hash.  It's  
   probably reasonably unique, but I'd be a bit nervous about it.

Agreed.  I'd XOR (Bitwise.BitXor) the MD5 sum bytes.

The 2^16 limit may still cause problems: running the birthday problem
on 2^16 values will give you a surprizingly small number before there
is a 50/50 chance of a collision.  I haven't done the math, but I
would guess it would be something like 1000 strings at most.

Craig

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>