realbasic-nug
[Top] [All Lists]

Re: Advice on Generating Unique Digits From String

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: Advice on Generating Unique Digits From String
From: Joe Strout <joe at inspiringapps dot com>
Date: Tue, 30 Oct 2007 13:01:59 -0600
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>
On Oct 30, 2007, at 12:34 PM, Kimball Larsen wrote:

> So, I have a need to take any old string of any length, in any
> encoding, with any content (ok, it will typically be 32 chars or
> less, but that's not important - you'll see why in a moment) and
> convert it into a short(ish) number in integer form.

  Dim v As Variant = myString
  return v.Hash

(or v.Hash mod whatever your maximum allowable value is).


>    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.

Best,
- Joe

--
Joe Strout
Inspiring Applications, Inc.
http://www.InspiringApps.com



_______________________________________________
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>