r/pythonhelp • u/Gnarmi • Feb 07 '24
Generating white noise?
Hello! I'm looking to generate simple white noise in python, but can't find any proper way to do it. I want to be able to take a sample from the noise by passing a coordinate, and for the noise to be infinite* (not a fixed size is what I mean by that).I can find resources for perlin noise (smooth noise), but none for white noise. Thanks for any help!
Something like this:
class Noise:
def __init__(self, frequency: int = 50):
"""Create noise. Frequency is the frequency of white pixels. 1 means roughly every other pixel is white, 100 means roughly every hundredth pixel is white."""
self.frequency = frequency
def get_sample(self, x, y) -> int:
"""Gets a sample of the noise at specified coordinates. Returns 1 if white, 0 if black"""
# return noise sample