Python 如何随机化“种子”;“噪音”;图书馆

Python 如何随机化“种子”;“噪音”;图书馆,python,python-2.7,perlin-noise,noise-generator,Python,Python 2.7,Perlin Noise,Noise Generator,我想创建一个带有柏林噪波的二维浮点数列表。我希望每次运行程序时生成的值都不同。但是,我不确定如何为我在GitHub上找到的噪波库提供随机种子 如何使程序在每次运行时生成不同的值 我的代码: from __future__ import division import noise import math from singleton import ST def create_map_list(): """ This creates a 2D list of floats usi

我想创建一个带有柏林噪波的二维浮点数列表。我希望每次运行程序时生成的值都不同。但是,我不确定如何为我在GitHub上找到的噪波库提供随机种子

如何使程序在每次运行时生成不同的值

我的代码:

from __future__ import division
import noise
import math
from singleton import ST


def create_map_list():
    """
    This creates a 2D list of floats using the noise library. It then assigns
    ST.map_list to the list created. The range of the floats inside the list
    is [0, 1].
    """

    # used to normalize noise to [0, 1]
    min_val = -math.sqrt(2) / 2
    max_val = abs(min_val)

    map_list = []

    for y in range(0, ST.MAP_HEIGHT):
        row = []

        for x in range(0, ST.MAP_WIDTH):
            nx = x / ST.MAP_WIDTH - 0.5
            ny = y / ST.MAP_HEIGHT - 0.5
            row.append((noise.pnoise2(nx, ny, 8) - min_val) / (max_val - min_val))

        map_list.append(row )

    ST.map_list = map_list

噪波库不支持种子。在实际状态下,不能有随机输出

但是,已经发布了一篇文章来解决这一点


为此,您必须在获得修改后的代码后重建库。(
python setup.py install

一种简单的方法是在noise函数中将一个随机数加到
x
y
,这样您也可以使用
random.seed()。我正在进行一个Minecraft world generation项目,我正在使用噪音。

谢谢你,谢谢你回答这么老的问题。