Excel allows us to get a random card using the INDEX and RANDBETWEEN functions. This step by step tutorial will assist all levels of Excel users to create a random playing card generator in Excel.
Figure 1. The final result of the random playing card generator
Syntax of the INDEX formula
The generic formula for the INDEX function is:
=INDEX(array, row_num, column_num)
The parameters of the INDEX function are:
- array – a range of cells where we want to get a data
- row_num – a number of a row in the array for which we want to get a value
- column_num – a column in the array which returns a value.
Syntax of the RANDBETWEEN formula
The parameters of the RANDBETWEEN function are:
- bottom – a value from which we want to get a random value
- top – a value to which we want to get a random value
Setting up Our Data for the Random Playing Card Generator
In the array B1:BA1 we have 52 playing cards while in the cell C4 will be placed the random card result.
To insert the card in the cell, we need to follow these steps:
- Select cell B1 and click on it
- Under the tab Insert and section Symbols choose Symbol
- Click Symbols and choose Font Segoe UI Symbol
- Find the card, click Insert tab and then Close tab
- Repeat this steps for other 51 cards
Figure 2. Data that we will use in the example
Get a Random Playing Card Generator in Excel
In the cell C4, we want to get the random playing card from the range B1:BA1.
The formula looks like:
In the INDEX function, the parameter array is the cell range $B$1:$BA$1. The row_num is 0 while the column_num is the formula
RANDBETWEEN(1,52). The RANDBETWEEN parameter bottom is 1, while the top is 52.
To apply the formula, we need to follow these steps:
- Select cell C4 and click on it
- Insert the formula:
- Press enter.
Figure 3. Get a random playing card with INDEX and RANDBETWEEN functions
With INDEX function we want to get the card from the array B1:BA1. The playing card in the cell C3 should be the random card. That’s why we use the RANDBETWEEN function in the column argument of the INDEX function. The RANDBETWEEN function result is 14 and final formula result is the card from the cell O1.
Most of the time, the problem you will need to solve will be more complex than a simple application of a formula or function. If you want to save hours of research and frustration, try our live Excelchat service! Our Excel Experts are available 24/7 to answer any Excel question you may have. We guarantee a connection within 30 seconds and a customized solution within 20 minutes.