Repeating Things

## Introduction

In the last section you learned about the `selectOne` property. That might have got you thinking: Can I select *more than one* item? Yes! You can select as many as you like.

## Examples

### `selectMany`

```
character = {{a-z}|{A-Z}|{0-9}}
tenCharacters = [character.selectMany(10)]

```

What's going on here? Well, first, we've nested a bunch of curly blocks to choose a random alphanumeric character. But now we do something new. The `selectMany` property is like the others we've seen so far except for one glaring difference: It must always be followed by a pair of parentheses (normal backets) that have a number inside them. That number specifies how many times we want to pull an item from the `[character]` "list". Here we've chosen to make 10 selections. So now if we evaluate `[tenCharacters]`, it'll result in something like: "j63iJY90qm".

Without the `selectMany` property, we'd need to do something like this:

```

```

And that wouldn't be fun. You can also select a *random* number of items as follows: `[character.selectMany(3,10)]`. That'll select a random number of characters between 3 and 10 (inclusive). See how that works? Inside the parentheses we put 2 numbers, separated by a comma - the minimum, then the maximum.

### `joinItems`

What if you want to join your selected items with a comma? For example, you might have a `[fruit]` list and you'd like to produce a sentence like: "My favourite fruits are: oranges, mangos, bananas, pears, apples, blueberries and grapes." Here's where we need the `joinItems` property:

```
sentence
  My favourite fruits are: [fruit.selectMany(5).joinItems(", ")] and [fruit].

```

The `joinItems` property also requires an input via the use of parentheses. Unlike number-based inputs, text-based inputs must be wrapped in quotation marks. So all `.joinItems(", ")` does is put `,`  (comma+space) in between each of the 5 items.

**Advanced Tip**We use quotation marks around text that we give to the `joinItems` property, but what if you'd like to use quotation marks within that text? In that case you need to put a backslash character before them. For example:

```
sentence = My favourite fruits are: "[fruit.selectMany(2).joinItems("\", \"")]" and "[fruit]".

```

I've colored text inside the quotes to try to make it less visually confusing. All it's doing is putting `", "` (quotes *included*) in-between each of our 3 randomly selected fruits, so it'd result in something like: My favourite fruits are: "grapes", "bananas" and "plums".

Quotes are a special character inside square blocks, and so we need to put a backslash before them whenever we want to use them in their "literal"/textual sense.
### Using a Variable

We could also select a random number of items like this:

```
num = {3-6}
sentence
  My favourite fruits are: [fruit.selectMany(num).joinItems(", ")] and [fruit].

```

Pretty cool, hey? In case you missed it, we're defining `[num]` as a random number between 3 and 6, and then we're using that random number as the input to the `selectMany` property. Note that there are **not** any square brackets around `num`. That's because *we're already inside square brackets*, so we can reference lists *by their plain old names*.

Note also that we **cannot** put curly bracket blocks directly inside square blocks *unless they are enclosed in quotation marks*. If you stick around for the advanced tutorial, you can learn why (hint: curly brackets have a different meaning when they're inside square brackets). Worth repeating yet again: **When inside square brackets you should reference lists directly by their name, rather than putting square brackets around their name.**

A reminder: You should name your lists only with letters, numbers and underscores. Your list names shouldn't contain spaces and shouldn't start with a number. Also, list names are case-sensitive. Your list *items*, on the other hand, can contain any text at all.

> **Pro tip:** If you want to join *all* the items in your list together (in the order you've defined them), you can just do this: `[fruit.joinItems(", ")]`. This can come in handy sometimes for defining "multi-line items".
>
>

### `selectUnique`

This "fruits" example is a good illustration of where we'd really like each selected item to be different to the others. We don't want something like: "My favourite fruits are: grapes, grapes, pears, …" So how do we prevent this sort of thing from occuring? This is where `selectUnique` comes in handy. `selectUnique` is just like `selectMany`, except that it never selects the same item twice:

```
sentence
  My favourite fruits are [fruit.selectUnique(3).joinItems(", ")].

```

Simple, right? But notice that `[sentence]` will result in something like "My favourite fruits are grapes, blueberries, watermelon." when ideally, we'd like it to be more gramatically correct: "My favourite fruits are grapes, blueberries **and** watermelon." It's evident that we'll often need a more powerful approach to selecting unique items from a list, and that's exactly what the next section is about.

Learn more stuff