python parallel computing: split keyspace to give each node a range to work on
Question: My question is rather complicated for me to explain, as i'm not really good at
maths, but i'll try to be as clear as possible.

I'm trying to code a cluster in python, which will generate words given a
charset (i.e. with lowercase: aaaa, aaab, aaac, ..., zzzz) and make various
operations on them. I'm searching how to calculate, given the charset and the
number of nodes, what range each node should work on (i.e.: node1: aaaa-azzz,
node2: baaa-czzz, node3: daaa-ezzz, ...). Is it possible to make an algorithm
that could compute this, and if it is, how could i implement this in python?

I really don't know how to do that, so any help would be much appreciated


Answer: Any way that you could compute a small integer from the string would be fine
for clustering. For example, compute a hash with md5, and look at a byte of
it:

    
    
    import hashlib
    
    s = "aaac"
    num_nodes = 5 # or whatever
    m = hashlib.md5(s)
    node = ord(m.digest()[0]) % num_nodes
    
    print node  # prints 2
    

This won't guarantee to evenly distribute all the strings, but it will be
close.

