Unique Selections

## Introduction

As we saw in the last section, we sometimes want random selections that aren't the same as previous selections. The `selectUnique` function is just like `selectMany`, except that it won't choose the same item from the list twice. `[animal.selectUnique(5)]` will select 5 unique items from the list called "animal". `[animal.selectUnique(3,20)]` will select a random number of animals between 3 and 20.

## `consumableList`

But sometimes the `selectUnique` function is a little too simplistic. What if we want to spread our unique selections throughout a paragraph of text, rather than just selecting a big list of them all at once?

This is where a "**consumable list**" comes in handy. When you randomly select an item from a *consumable* list, that item disappears from the list and cannot be chosen again - the item is "consumed". Creating a consumable list is pretty easy. We just take a normal list that we've made, and add the "consumableList" command: `[cl = animal.consumableList]`. We've now created `[cl]`, which is a **consumable** list of animals.

It's a completely separate (consumable) copy of the original. Whenever `[cl]` is evaluated, it outputs an animal, and removes that animal from the "cl" list so that next time `[cl]` is evaluated it definitely won't output that animal again. Let's look at an example:

```
topic
  trans rights
	animal rights
	science
	mathematics
	...

sentence
  She mostly writes about [t = topic.consumableList] and [t].

```

So far, we've seen properties like `selectOne` (which grabs a random item from the list) and `pluralForm` (which grabs a random item from the list and pluralizes it). The `consumableList` property actually creates an exact copy of the whole list but alters this new list so that when we select items from it, those items are removed and cannot be chosen again. So `[t = topic.consumableList]` copies the whole `[topic]` list, makes it "consumable", and then makes it accessible via `[t]`.

As well as creating a consumable list called `t`, the code `[t = topic.consumableList]` also outputs (and consequently "consumes") the first item from that `t` list. So in the above example `[sentence]` would output something like: "She mostly writes about science and trans rights." What if you want to create a consumable list, but not yet output the first item? That's explained in the "*Commas In Square Blocks*" section below (spoiler: you'd just write `[t = topic.consumableList, ""]`).

### Storing Item Selected from `consumableList`

Here's a more complex example for you to think about. We want to select two random non-duplicate things she writes about, and then re-use the second one in a follow-on sentence.

```
sentence
  She mostly writes about [t = topic.consumableList] and [a = t.selectOne]. Her last post was about [a].

```

Can you see what's happening there? We make a consumable list called `t` and output the first item at the same time, then we get the second item and put it in a 1-item list called `a`, and output that item at the same time. Then we use `a` again for the third selection. So we end up with a sentence like "She mostly writes about mathematics and animal rights. Her last post was about animal rights." The last two topics are the same and they're different to the first one.

> You might be wondering why we need to write `[a = t.selectOne]` instead of just `[a = t]`? The answer is that `[a = t]` would make `a` a direct reference to the whole `t` list, rather than a *specific, randomly-chosen item* from `t`. So `[a = t]` would mean that writing `[a]` would then be the same as writing `[t]` - they'd be the same thing. We write `[a = t.selectOne]` to select a random item from `t` and put it in `a` so we can use it again later (see Aliasing).
>
> But then, when you write `[t]`, why doesn't it output the *whole* list? The answer is that Perchance "sneakily" does a behind-the-scenes `selectOne` on the output of square blocks so that Perchance code is "neater" to write. I.e. so you can write `[t]` instead of `[t.selectOne]`. This, unfortunately, can lead to the above confusion. But hopefully this explanation clears things up!
>
>

Learn more stuff