1

パーリン ノイズを使用してフロートの 2D リストを作成したいと考えています。プログラムを実行するたびに、生成される値が異なるようにしたいと考えています。ただし、ここで 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
4

2 に答える 2