Search code examples
pythonpython-3.xprocedural-generationperlin-noise

How does one choose the seed using noise.py module


How does one choose the seed for the noise module in python?

I have this bit of code:

from noise import snoise2
terrainTiles[varX][varY].set_elevation(snoise2(x=varX/20,y=varY/20,octaves=1))

And it does create proper noise; however, i am unable to change the seed. I have been searching for hours and have yet to find a solution. Thanks!

Simplier example of the function:

from noise inport snoise2
print(snoise2(10,10))

SOLUTION

I found a solution separate of noise.py. I used this script I found on github: https://gist.github.com/eevee/26f547457522755cb1fb8739d0ea89a1

This also does not have a seed function, BUT, it has an unbias function so that far out coordinates still have proper noise. I used a 3 dimensional noise function where the 3rd dimension value is essentially the seed. Code shown here:

#generate world seed
worldSeed = random.randint(0, 100000000)

#generate noise objects. I hate this but im ghettoing it so that the 3rd dimension value is essentially the seed, I hate this but it works
elevationNoise = noise.PerlinNoiseFactory(dimension=3, octaves=1, unbias=True)

and it being applied to a value:

terrainTiles[varX][varY].set_elevation(elevationNoise(varX/20,varY/20,worldSeed)*1.15)

Solution

  • there is no seed parameter so to say, however there is a base parameter which you can modify which specifies an offset for the noise coordinates. For example:

    import random
    from noise import snoise2
    
    seed = random.random()
    print snoise2(10, 10, base=seed)
    

    where base requires a float

    so for your first example you should just be able to add base=seed to your snoise2(..):

    terrainTiles[varX][varY].set_elevation(snoise2(x=varX/20,y=varY/20,octaves=1, base=seed))