# Random values from array

**URL:** https://discourse.processing.org/t/random-values-from-array/15084
**Category:** Coding Questions
**Created:** [October 31, 2019, 6:52pm UTC](https://discourse.processing.org/t/random-values-from-array/15084 "2019-10-31T18:52:37Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![San](https://avatars.discourse-cdn.com/v4/letter/s/ba9def/32.png) [@San](https://discourse.processing.org/u/San)
#### Post date: [October 31, 2019, 6:52pm UTC](https://discourse.processing.org/t/random-values-from-array/15084/1 "2019-10-31T18:52:37Z")

</div>

I want to select random values from this array. But if I run it, it sometimes has the same number in it twice. I want to have each number just one time but in a different order everytime I run it.

[image|690x188](https://discourse.processing.org/uploads/short-url/8r9EFO2sVAozdkx4OLJzoWNp4Tb.png)

---

<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: [October 31, 2019, 7:44pm UTC](https://discourse.processing.org/t/random-values-from-array/15084/2 "2019-10-31T19:44:08Z")

</div>

- [Non-repeating numbers - Processing 2.x and 3.x Forum](http://Forum.Processing.org/two/discussion/27692/non-repeating-numbers#Item_5)

> [@Repeating and randomizing string arrays](https://discourse.processing.org/t/repeating-and-randomizing-string-arrays/10811/6):
>
> The shuffle() function from the 1st link I’ve posted is for arrays of datatype int only: @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; } For object-typed arrays, we need to convert it, like this: @SafeVarargs final \<T\> T[] shuffle(final T... arr) { if (arr == null) return null; …
