[sugar] python hash function limited to specific table size?

Bert Freudenberg bert
Fri Mar 16 04:15:39 EDT 2007

On Mar 16, 2007, at 3:29 , Dan Williams wrote:

> On Thu, 2007-03-15 at 20:11 +0100, Bert Freudenberg wrote:
>> On Mar 15, 2007, at 19:24 , Mike C. Fletcher wrote:
>> Well, what I read between Dan's lines was that he does not actually
>> have a dictionary, but wants to select one of 500 values based on a
>> string hash. Another use would be, for example, to make a seed for a
>> random generator that then would make a repeatable sequence, perhaps
>> to assign a color for a nickname.
> Almost exactly right.  We have 520 color pairs that look good in both
> B&W and Color modes.  And we have wireless access points with an SSID
> and capabilities which never change from boot to boot.
> So, I want to assign the _same_ color pair to the hash of (SSID+caps)
> every single time I see that wireless network.  hash(ssid+str(caps))
> works, except that's within the range [-sys.maxint, sys.maxint], which
> is waaay out of the range of [0, 519] which I can use to index into  
> the
> color table.  As Bert suggested, hash(ssid+str(caps)) % len 
> (color_table)
> works more or less.

Cool. Can't wait to see what my AP is going to look like ;)

But maybe this could be used for assigning the XO color in the first  
login screen, too. Would take away one of the confusing options, and  
there surely will be UI to change the color later, right?

- Bert -

More information about the Sugar-devel mailing list