Random & noise
On this page · 6 entries
Random
Random(float max)Random(min, max)
Uniform random float.
RandomGaussian
RandomGaussian() → float
Normally distributed (mean 0, standard deviation 1).
RandomSeed
RandomSeed(int seed)
Reseeds the shared random generator.
Noise
Noise(float x)Noise(x, y) → float
Smooth pseudo-random value in [0, 1].
NoiseSeed · NoiseDetail
NoiseSeed(int seed)NoiseDetail(int octaves, float falloff = 0.5f)
Reshuffles the noise permutation table, or changes octaves and falloff.
Runnable example
A complete sketch using this section. Test in Dana opens it in the IDE, or paste it into a new tab and press Run.
// Random scatters, Noise flows: the same landscape, two ways. public class Terrain : Sketch { public override void Setup() => Size(600, 300); public override void Draw() { Background(250); float t = FrameCount * 0.01f; // Top: Random() -- jumpy. Stroke(200, 80, 60); NoFill(); BeginShape(); RandomSeed(FrameCount / 10); for (int x = 0; x <= Width; x += 10) Vertex(x, 80 + Random(-40, 40)); EndShape(); // Bottom: Noise() -- smooth, and it moves when t changes. Stroke(60, 120, 200); BeginShape(); for (int x = 0; x <= Width; x += 5) Vertex(x, 220 + (Noise(x * 0.01f, t) - 0.5f) * 160); EndShape(); Fill(30); NoStroke(); Text("Random()", 10, 20); Text("Noise()", 10, 160); } }