How to Generate Seeded 2D White Noise
<p>I am trying to write a function so that <code>f(x, y, seed)</code> returns some float between 0.0 and 1.0. <code>x</code> and <code>y</code> are two floats, and the <code>seed</code> would be an integer. The result should look like a random number, but using the same arguments will always return the same result. I am planning to use this for terrain generation (using Perlin Noise), but the effect should be that white noise could be created from a given seed (with the x and y arguments corresponding to positions in the image).</p>

<p>I have looked into using hash functions to achieve this, but all of the ones I have come across either don't accept floats, don't produce uniform results (so that each number between 0.0 and 1.0 is equally likely), show an obvious pattern, or the result doesn't change much for close co-ordinates)</p>

<p>Depends on what distribution you're looking to achieve, but e.g. for uniform distribution over a known image size you could do:</p>

<pre><code>width = 100

from random import random
def f(x, y, seed):
    rng = random(seed)
    rng.jumpahead(x * width + y)
    return rng.random()
</code></pre>

<p>Alternatively, if you have the ordinal index of the pixel available instead of x and y, you don't need the grid size:</p>

<pre><code>from random import random
def f(n, seed):
    rng = random(seed)
    rng.jumpahead(n)
    return rng.random()
</code></pre>

python random hash noise