python lib for custom hash function
<p>I need a hash function to take a sequence of decimal numbers and return a decimal number as hash value.</p>

<p>for example:</p>

<pre><code>&gt;&gt; def my_simple_hash(*args):
    return reduce(lambda x1, x2: 2*x1 + x2,  args) 

&gt;&gt;&gt; my_simple_hash(1,3,4)
14
&gt;&gt;&gt; my_simple_hash(1,4,3)
15
&gt;&gt;&gt; my_simple_hash(4,3,1)
23
</code></pre>

<p>My questions are:</p>

<ol>
<li>does python has a built-in lib to do this more efficiently?  </li>
<li>how could I make the output hash value in a relative small range?</li>
</ol>

<p>Question 2 explanation:</p>

<p>because 1, 3, 4 has six different combinations as following:</p>

<pre><code>1,3,4
1,4,3
3,1,4
3,4,1
4,1,3
4,3,1
</code></pre>

<p>the corresponding output is <code>[14, 15, 18, 21, 21, 23]</code>, and I expect the hash values of the <code>six</code> output would be something like <code>[1,2,3,4,6]</code>(a small range)</p>

<p>any suggestions would be appreciated. 
thanks in advance :-)</p>

<p>If you just want to hash a number sequence you can do</p>

<pre><code>def my_hash(*args):
    return hash(args)
</code></pre>

<p>which returns the <a href="https://docs.python.org/3/library/functions.html#hash" rel="nofollow">hash</a> (for the current run of the program) of the args-tuple (<code>hash</code> is fast and well tested for builtin-types) - but this is still most often a large number.</p>

<p>For getting a smaller value you can take the modulo like</p>

<pre><code>def my_hash(*args):
    return hash(args)%10 # or whatever number you like
</code></pre>

<p>Actually you could also use</p>

<pre><code>def my_hash(*args):
    return sum(args)%10 # or whatever number you like
</code></pre>

<p>which doesnt change between runs of the program but <code>sum</code> does not distribute the results evenly at all.</p>

<p><strong>Warning: These are not cryptographical hashes</strong></p>

python