Robin Becker <[EMAIL PROTECTED]> writes:
> >> Is the any way to get an efficient 16bit hash in python?
> > hash(obj)&65535
> >   - Josiah
> yes I thought of that, but cannot figure out if the internal hash
> really distributes the bits evenly. Particularly since it seems to
> treat integers etc as special cases

The built-in hash function doesn't attempt even distribution, it tries
to make sure that inputs with small differences hash to distinct
values.  If you want something really near-random, try

    import sha
    hash = int(sha.new(repr(obj)).hexdigest()[:4], 16)

It won't be super-fast but hey, you're using Python.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to