# Randomizing levels

**URL:** <https://discourse.processing.org/t/randomizing-levels/11572>\
**Category:** Coding Questions\
**Created:** [May 25, 2019, 1:19am UTC](https://discourse.processing.org/t/randomizing-levels/11572 "2019-05-25T01:19:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![clueless\_coder](https://avatars.discourse-cdn.com/v4/letter/c/34f0e0/32.png) [@clueless\_coder](https://discourse.processing.org/u/clueless_coder)\
**Post date:** [May 25, 2019, 1:19am UTC](https://discourse.processing.org/t/randomizing-levels/11572/1 "2019-05-25T01:19:45Z")

</div>

I’m trying to code a game in which clicking ‘play’ would result in the player getting a random level out of a few set levels. However, the problem is that the levels have to be non-repeating. Does anyone know how to achieve something like this?

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [May 25, 2019, 1:56am UTC](https://discourse.processing.org/t/randomizing-levels/11572/2 "2019-05-25T01:56:51Z")

</div>

using the arraylist might help:

```auto
IntList levels;
int maxi = 5, use;

void setup() {
  levels = new IntList(); // makes a empty list
  for ( int i = 0; i < maxi; i++) levels.append(i); // fills it with ascending numbers
  //println(levels);
  levels.shuffle(); // makes it random
  println(levels);  
  use_next();
}

void draw() {
}

void keyPressed() {
  if ( key == ' ' ) use_next();
}

void use_next() {
  if ( levels.size() > 0 ) {
    use = levels.get(0); // use the first one
    levels.remove(0); // and delete it from the list
    println("use: "+use+" array: "+levels);
  }
}

```
