# Noise Buffering

**URL:** <https://discourse.processing.org/t/noise-buffering/14640>\
**Category:** Coding Questions\
**Created:** [October 12, 2019, 10:13pm UTC](https://discourse.processing.org/t/noise-buffering/14640 "2019-10-12T22:13:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![LordCacops](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lordcacops/32/2280_2.png) [@LordCacops](https://discourse.processing.org/u/LordCacops)\
**Post date:** [October 12, 2019, 10:13pm UTC](https://discourse.processing.org/t/noise-buffering/14640/1 "2019-10-12T22:13:41Z")

</div>

Hey there!

I am in a necessity to know how to create a buffer of perlin noise so that I can access that same stable noise data in different scenarios, and across different runs of the same program. In another thread someone said something about noise buffering and I will like to know what prior implementations have been done to achieve this. Thanks.

---

<div class="post-metadata">

**Author:** ![figraham](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/figraham/32/4161_2.png) [@figraham](https://discourse.processing.org/u/figraham)\
**Post date:** [October 13, 2019, 7:48am UTC](https://discourse.processing.org/t/noise-buffering/14640/2 "2019-10-13T07:48:09Z")

</div>

I’d suggest creating a sketch that is just for making a csv of noise data. And then load that csv in the sketch you want to use it in.

Here’s a basic example:

```auto
Table t;

void setup() {
  t = new Table();
  t.addColumn("noise");
  
  for (int i = 0; i < 100; i++) {
    TableRow r = t.addRow();
    r.setFloat("noise", noise(i));
  }
  
  saveTable(t, "perlin-noise.csv");
  exit();
}

```

```auto
float[] bufferNoise;

void setup() {
  bufferNoise = loadNoise();
  println(bufferNoise);
}

float[] loadNoise() {
  Table t = loadTable("perlin-noise.csv", "header");
  float[] a = new float[t.getRowCount()];
  for (int i = 0; i < t.getRowCount(); i++) {
    TableRow r = t.getRow(i);
    a[i] = r.getFloat("noise");
  }
  return a;
}

```

Don’t forget to copy the csv from the first sketch into the second sketch’s data folder.

Using this method will make your sketch take up more memory and setup will run slower especially if you load a huge file but shouldn’t effect your program speed after setup.

There’s less flexibility because you can’t really save an infinite amount of noise in a buffer but you could make it a perfect loop by doing something like:

```auto
float noiseScale = 1;
int max = 100;
for (int i = 0; i < max; i++) {
  TableRow r = t.addRow();
  float theta = map(i, 0, max, 0, TWO_PI);
  r.setFloat("noise", noise(noiseScale * cos(theta), noiseScale * sin(theta)));
}

```

---

<div class="post-metadata">

**Author:** ![benja](https://avatars.discourse-cdn.com/v4/letter/b/fbc32d/32.png) [@benja](https://discourse.processing.org/u/benja)\
**Post date:** [October 13, 2019, 8:23pm UTC](https://discourse.processing.org/t/noise-buffering/14640/3 "2019-10-13T20:23:33Z")

</div>

To me it sounds, like [noiseSeed()](https://processing.org/reference/noiseSeed_.html) would actually do exactly what you need.

---

<div class="post-metadata">

**Author:** ![figraham](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/figraham/32/4161_2.png) [@figraham](https://discourse.processing.org/u/figraham)\
**Post date:** [October 14, 2019, 7:04am UTC](https://discourse.processing.org/t/noise-buffering/14640/4 "2019-10-14T07:04:02Z")

</div>

Definitely a much simpler solution. I was having problems with noise seed starting at the same number but then diverging (from the same seed in other runs) the farther you got from zero. This was a year or two ago. Anyways I can’t reproduce the problem now so either something change or more likely I was doing something stupid.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [October 19, 2019, 2:49pm UTC](https://discourse.processing.org/t/noise-buffering/14640/5 "2019-10-19T14:49:30Z")

</div>

If you are trying to use the same (seeded) noise between Processing / p5.js / processing.py sketches with consistent results, you can also use CommonRandom. This gives cross-mode stable output from any given seed.

> [@Cross-language random numbers](https://discourse.processing.org/t/cross-language-random-numbers/3474):
>
> I have developed a set of demo sketches that implement simple cross-language random numbers. The goal is to make it easy to adapt a sketch between Processing (Java), p5.js (JavaScript), or Processing.py (Python) such that passing the same random seed to each version will generate the same “random” playback from a generative artwork. This is currently not possible using the core modes / libraries, as they each use different underlying systems for generating random numbers. One solution is to im…

---

<div class="post-metadata">

**Author:** ![LordCacops](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lordcacops/32/2280_2.png) [@LordCacops](https://discourse.processing.org/u/LordCacops)\
**Post date:** [October 26, 2019, 7:51pm UTC](https://discourse.processing.org/t/noise-buffering/14640/6 "2019-10-26T19:51:54Z")

</div>

> [@benja](#):
>
> To me it sounds, like [noiseSeed()](https://processing.org/reference/noiseSeed_.html) would actually do exactly what you need.

It does! Thanks a bunch!
