# Random words from text file - how to avoid duplicate index numbers?

**URL:** <https://discourse.processing.org/t/random-words-from-text-file-how-to-avoid-duplicate-index-numbers/21456>\
**Category:** Coding Questions\
**Created:** [May 31, 2020, 1:04pm UTC](https://discourse.processing.org/t/random-words-from-text-file-how-to-avoid-duplicate-index-numbers/21456 "2020-05-31T13:04:18Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [May 31, 2020, 4:27pm UTC](https://discourse.processing.org/t/random-words-from-text-file-how-to-avoid-duplicate-index-numbers/21456/3 "2020-05-31T16:27:10Z")

</div>

> [@Random numbers 1-13 that don't repeat more than once](https://discourse.processing.org/t/random-numbers-1-13-that-dont-repeat-more-than-once/17269/5):
>
> final IntList sequence = IntList.fromRange(1, 14); println(sequence);//IntList size=13 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] sequence.shuffle(this); println(sequence); exit();

> [@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; …

---

_[View the full topic](https://discourse.processing.org/t/random-words-from-text-file-how-to-avoid-duplicate-index-numbers/21456)._
