# Random Numbers

> Learn how to add randomness to your PandaSuite projects using the Random Number variable and the Shuffle function.

https://docs.pandasuite.com/essentials/gamification/random/

**In your interactive projects, a touch of unpredictability can make the experience more engaging and varied. With PandaSuite, two complementary tools let you add surprise to your scenarios: the Random Number variable and the Shuffle function.**

## Why use random mechanisms?

Randomness is useful for:

- Varying the content displayed on each launch.
- Offering unique experiences to each user.
- Simulating random behaviors (draws, games…).
- Shuffling elements of a list or a group.

In PandaSuite, this is achieved thanks to:

- The **Random Number** variable, which generates a floating-point number between 0 and 1.
- The **Shuffle** function, which randomly rearranges the order of a list or group of elements.

## The Random Number variable

### What is it?

The system variable **Random Number** generates a new value on each refresh.\
It returns a decimal number between 0 and 1 (for example: 0.274 or 0.859).

This value can then be used in logical conditions, calculations, or displayed directly.

### How to use it?

You can insert the **Random Number** variable in your scenarios to:

- Compare this value to a threshold (example: if > 0.5…).
- Multiply this value by an integer to get a range (example: Random Number × 5 gives a value between 0 and 5).
- Create random effects without complex calculations.

> **Info**
>
> 💡 To get an integer between 1 and N, use the following formula: Round(Random
> Number × N) + 1

### Example: display a random card

- Create a [Collection](https://docs.pandasuite.com/essentials/data/collection/) containing all your cards.
- On the button, trigger an action to set the value of a variable *random\_index*

```
random_index = Round(Random Number × (Count-1)) + 1
(where Count is the number of cards in the collection)
```

- Dynamically display the corresponding card based on the value of the *random\_index* variable.

[Image: Data window of the draw button's Create/Update Data action: Random number, then Multiply and Round; the action is framed on the right]

## The Shuffle function

## The Shuffle Function

The [**Shuffle** function](https://docs.pandasuite.com/essentials/data/functions/) allows you to randomly rearrange the order of elements in a **[Table](https://docs.pandasuite.com/essentials/data/data-types/#array)** or a **[Collection](https://docs.pandasuite.com/essentials/data/data-types/#collection)**.\
If applied to a **Table**, it returns a **Table**.\
If applied to a **Collection**, it returns a **Multi-reference**.\
You can also set a limit to control the number of elements returned.

### How to use it?

1. Place the elements you want to shuffle in a **Collection**.
2. In this example, create a **Multi-reference** variable that points to this **Collection**.
3. Add an action to initialize this newly created variable.
4. In the **Value**, start from your collection and use the **Shuffle** function.
5. In the **Parameters**, specify the number of elements to include in the shuffled result.

[Image: Data window: the cards collection followed by the Shuffle function, which returns a Multi-reference of two random cards]

### Use cases

- Shuffle quiz questions.
- Reorder images or cards for a memory game.
- Create dynamic lists or carousels.

## Additional resources

[Template: Random Cards](https://pandasuite.com/dashboard/use-template/c0r3GpYBaHn0WhDCjnLF)
