# Pure Java random string code to Processing random string code

**URL:** <https://discourse.processing.org/t/pure-java-random-string-code-to-processing-random-string-code/36072>\
**Category:** Coding Questions\
**Created:** [April 1, 2022, 8:19pm UTC](https://discourse.processing.org/t/pure-java-random-string-code-to-processing-random-string-code/36072 "2022-04-01T20:19:11Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [April 2, 2022, 1:56pm UTC](https://discourse.processing.org/t/pure-java-random-string-code-to-processing-random-string-code/36072/5 "2022-04-02T13:56:10Z")

</div>

> [@Chrisir](#):
>
> You can’t have a class inside a function.

Actually Java can have keyword `class` inside a function!

However its usage is rare & not so many folks know about it: 🤓

```auto
void settings() {
  size(600, 400);
  noLoop();

  class classInsideFunction extends PApplet {
    public void settings() {
      size(400, 300);
      println(sketchPath());
    }

    public void setup() {
      frameRate(1);
    }

    public void draw() {
      background((color) random(#000000));
    }
  }

  final String[] switches = {
    ARGS_SKETCH_FOLDER + '=' + sketchPath(), 
    ARGS_LOCATION + "=100,100", 
    "" 
  };

  runSketch(switches, new classInsideFunction());
}

void draw() {
  background((color) random(#000000));
}

void mousePressed() {
  redraw = true;
}

void keyPressed() {
  mousePressed();
}

```

---

_[View the full topic](https://discourse.processing.org/t/pure-java-random-string-code-to-processing-random-string-code/36072)._
