Search code examples
processingperlin-noiserandom-seed

Printing Noise Seed of Processing Sketch


There is a function noiseSeed(int) to set the seed for a program, but is there any way to print the seed of a program when it begins?

I am making generative art sketches and it would be more convenient to store just a seed number for a result than an entire image.


Solution

  • You can't get the default random seed value.

    Check out Processing's source code (specifically the random() and randomSeed() functions) to see that Processing uses an instance of the Random class to generate random numbers. That class does not have a public way to access its seed value, and even if it did, the internalRandom used by Processing isn't accessible to you anyway.

    What you can do is create your own seed value and then store that in your own variable. Something like this:

    long seed;
    
    void setup(){
      seed = (long)random(1000);
      randomSeed(seed);
      println("Seed value: " + seed);
    }
    

    How you come up with that seed is up to you. Here I'm generating a random seed between 0 and 1000, but in real life it can be any long value.

    You could then also input this from the user in order to have repeatable random behavior based on the input value.