# Random Number Generation without Repetition

**URL:** https://discourse.processing.org/t/random-number-generation-without-repetition/4767
**Category:** Coding Questions
**Created:** [October 23, 2018, 2:12am UTC](https://discourse.processing.org/t/random-number-generation-without-repetition/4767 "2018-10-23T02:12:42Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![danielo](https://avatars.discourse-cdn.com/v4/letter/d/bbe5ce/32.png) [@danielo](https://discourse.processing.org/u/danielo)
#### Post date: [October 23, 2018, 2:12am UTC](https://discourse.processing.org/t/random-number-generation-without-repetition/4767/1 "2018-10-23T02:12:42Z")

</div>

I am trying to generate random numbers of a specified range (0-35, for example) without generating any number twice until all numbers have been generated once.

Thank you for any guidance.

Regards,

Daniel

---

<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 23, 2018, 2:51am UTC](https://discourse.processing.org/t/random-number-generation-without-repetition/4767/2 "2018-10-23T02:51:37Z")

</div>

- [Forum.Processing.org/two/discussion/27692/non-repeating-numbers](http://Forum.Processing.org/two/discussion/27692/non-repeating-numbers)

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [October 24, 2018, 5:59pm UTC](https://discourse.processing.org/t/random-number-generation-without-repetition/4767/3 "2018-10-24T17:59:08Z")

</div>

Note specifically that both IntList and FloatList have `shuffle()` built-in. From your description it sounds like you want ints?

- [https://processing.org/reference/IntList.html](https://processing.org/reference/IntList.html)
- [https://processing.org/reference/IntList\_shuffle\_.html](https://processing.org/reference/IntList_shuffle_.html)

So one approach is to make an ordered list, shuffle it, use it until you are done with it, then get another one.

```auto
void setup() {
  for (int i=0; i<3; i++) {
    int[] nums = scramble(10);
    println(nums);
    println();
  }
}

int[] scramble (int count) {
  IntList scrambler = new IntList();
  for (int i=0; i<count; i++) {
    scrambler.append(i);
  }
  scrambler.shuffle();
  return scrambler.array();
}

```

Output:

> **Summary**
>
> [0] 7  
> [1] 5  
> [2] 2  
> [3] 6  
> [4] 8  
> [5] 0  
> [6] 4  
> [7] 3  
> [8] 9  
> [9] 1
> 
> [0] 1  
> [1] 8  
> [2] 7  
> [3] 5  
> [4] 3  
> [5] 9  
> [6] 2  
> [7] 4  
> [8] 0  
> [9] 6
> 
> [0] 2  
> [1] 1  
> [2] 3  
> [3] 6  
> [4] 9  
> [5] 7  
> [6] 4  
> [7] 8  
> [8] 0  
> [9] 5

---

<div class="post-metadata">

### Author: ![r8th](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/r8th/32/5105_2.png) [@r8th](https://discourse.processing.org/u/r8th)
#### Post date: [August 5, 2020, 4:38pm UTC](https://discourse.processing.org/t/random-number-generation-without-repetition/4767/4 "2020-08-05T16:38:11Z")

</div>

Can something like this be done with words or names, for instance, to generate a random name picker that does not repeat words or names???  
Thanks!  
r8th

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [August 7, 2020, 3:21pm UTC](https://discourse.processing.org/t/random-number-generation-without-repetition/4767/5 "2020-08-07T15:21:51Z")

</div>

Hello,

This should answer your question:  
[https://processing.org/reference/StringList.html](https://processing.org/reference/StringList.html)

I also tried it.

`:)`
