# Questions about my Color Array

**URL:** <https://discourse.processing.org/t/questions-about-my-color-array/3110>\
**Category:** Coding Questions\
**Created:** [August 30, 2018, 2:17pm UTC](https://discourse.processing.org/t/questions-about-my-color-array/3110 "2018-08-30T14:17:18Z")\
**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:** [September 3, 2018, 3:37am UTC](https://discourse.processing.org/t/questions-about-my-color-array/3110/5 "2018-09-03T03:37:54Z")

</div>

> [@jeremydouglass](#):
>
> … because the while loop will run forever and never exit…

I didn’t bother warning about that b/c the _colors[]_ array already had 3 elements in it. 😌

BtW, here’s an even shorter version w/ just `while ()` instead of `do // while ()`: 😼

```auto
void pick() {
  int newIndex;
  while ((newIndex = (int) random(colors.length)) == index);
  index = newIndex;
}

```

Nonetheless, a custom **shuffle()** approach (from my previous posted link) is much more commendable: 😁

```java
@ SafeVarargs final int[] shuffle(final int... arr) {
  if (arr == null) return null;
 
  int idx = arr.length;
 
  while (idx > 1) { 
    final int rnd = (int) random(idx--), tmp = arr[idx];
    arr[idx] = arr[rnd];
    arr[rnd] = tmp;
  }
 
  return arr;
}

```

---

_[View the full topic](https://discourse.processing.org/t/questions-about-my-color-array/3110)._
