# randomSeed() reuse

**URL:** <https://discourse.processing.org/t/randomseed-reuse/32154>\
**Category:** Beginners\
**Created:** [September 8, 2021, 7:51am UTC](https://discourse.processing.org/t/randomseed-reuse/32154 "2021-09-08T07:51:31Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [September 9, 2021, 4:28pm UTC](https://discourse.processing.org/t/randomseed-reuse/32154/14 "2021-09-09T16:28:27Z")

</div>

I still don’t get your question.

What you would do for example is run a program like this:

```auto
long seed;

void setup() {
  seed = System.nanoTime(); // Get a random seed (will "always" be different for each execution)
  randomSeed(seed); // Set the seed of the random number generator
  println(seed); // Print out the seed used on screen
  
  // Do whatever you want to do to generate your image
 generateImage();
}

```

If there is an image for which you are happy with, then you can copy the seed written in the console.  
Let’s say I run the code for the first time. The seed printed in the console is: 123456. But I don’t like the outcome so I run the program again.  
This time the seed is: 987654 and I like the outcome. Then I can save that seed number.  
If later on I want to regenerate the same image I will alter the previous code like this:

```auto
long seed;

void setup() {
  // seed = System.nanoTime(); // No need for this anymore
  seed = 987654; // Set the seed to the value that generated the image I liked.
  randomSeed(seed); // Set the seed of the random number generator
  println(seed); // Print out the seed used on screen
  
  // Do whatever you want to do to generate your image
 generateImage();
}

```

---

_[View the full topic](https://discourse.processing.org/t/randomseed-reuse/32154)._
