How To Mac

How to Generate Random Numbers on Mac

Written by John

A random number generator will allow you to get random number every time you execute the application. There are many applications for random number generators. They have applications in computer simulation, cryptography, and other areas where the desired output is an unpredictable result.

Shortcuts is a built in free app on macOS Ventura and Monterey. Shortcuts app allows you to select a random number with a single click. All you need to do is set up a simple shortcut that can be executed to get a random number. You don’t need any other tool when you can conveniently use the random number picker shortcut you’ve created on Mac to generate random numbers.

In this tutorial, you will understand how to create a random number generator that gives random numbers on every execution of the shortcut.

How to Generate Random Numbers on Mac

Let us look at how we can generate one or more random numbers in a custom range.

The input range will be from 1 to 100. We will generate 5 numbers with no repeated numbers. These numbers will not be sorted. Follow the steps below to generate random numbers in a custom range on Mac.

Generate Random Numbers

Step 1: Launch the Shortcuts app in Application Folder. Select the ‘+’ button on the top-right of the application screen to create a new shortcut.

Step 2: Type ‘Run Shell Script’ in the search bar and drag the shortcut option to the left window to start building your shortcut.

Enter the following shell script command to create a number list from 1 to 100.

i=1
while [ $i -le 100 ]
do
        echo $i
        i=$(($i+1))
done

Make sure the Shell is set to ‘zsh’, Input is set to ‘input’, and Pass Input is set to ‘to stdin’.

Step 3: Search for ‘Split Text’ in the search box and drag the shortcut option below the ‘Run Shell Script’ action. Make sure the shortcut option is set as “Split Shell Script Result by New Lines“. You’ve instructed Mac to split the number list to a new line.

Step 4: Search for ‘Filter’ in the search box and drag the shortcut option below the “Split Shell Script Result by New Lines” action. Make sure the shortcut option is set as “Filter Split Text”, Sort by is set to ‘Random’, the ‘Limit’ checkbox is checked to Get 5 Files. You’ve instructed Mac to use Filter to choose 5 files with Random List.

Step 5: Search for ‘Set Variable’ in the search box and drag the shortcut option below the “Filter Split Text” action. Make sure the shortcut option is set as “Set variable Number to Files”.

Step 6: Search for ‘Text’ in the search box and drag the shortcut option below. Right click and select "Number".

Step 7: Search for ‘Quick Look’ in the search box and drag the shortcut option below the ‘Text’ action. Make sure the shortcut option is set as “Show Text in Quick Look”.

Generate 5 numbers with no repeated numbers

Name your shortcut as Generate Random Numbers and add an icon of your choice and color to identify it. Click on the ‘Shortcut Details’ option in the right sidebar and enable ‘Pin in Menu Bar’. This will add the shortcut to the menu bar to make it easier for you to generate a random number.

Random Choosing From a List

We will look at how we can perform random choosing from a list. The input range will be a list of names with no repeated names and not sorted.

Random Choosing From a List

Step 1: Open Shortcuts App and create a new shortcut.

Step 2: Type ‘Text’ in the search bar and drag the shortcut option to the left window to start building your shortcut. Copy and paste your name list to Text.

Step 3: Search for ‘Split Text’ in the search box and drag the shortcut option below the ‘Text’ action. Make sure the shortcut option is set as “Split Text by New Lines

Step 4: Search for ‘Filter’ in the search box and drag the shortcut option below the “Split Text by New Lines” action. Make sure the shortcut option is set as “Filter Split Text”, Sort by is set to ‘Random’, the ‘Limit’ checkbox is checked to Get 5 Files. You’ve instructed Mac to use Filter to create 5 random names from the list.

Step 5: Search for ‘Set Variable’ in the search box and drag the shortcut option below the “Filter Split Text” action. Make sure the shortcut option is set as “Set variable List to Files”.

Step 6: Search for ‘Text’ in the search box and drag the shortcut option below. Right click and select "List".

Search for ‘Quick Look’ in the search box and drag the shortcut option below the ‘Text’ action. Make sure the shortcut option is set as “Show Text in Quick Look”. Name your shortcut as ‘Random List’ and add an icon of your choice and color to identify it.

Click on the ‘Shortcut Details’ option in the right sidebar and enable ‘Pin in Menu Bar’. When you do this, you will add the shortcut to the menu bar to make it easier for you to choose a random list instantly.

Shortcuts app makes it easy to create a random number generator so that you don’t ever have to use other third-party tools to generate random numbers for application purposes. You can now save a lot of time by instantly using the number generator on Mac to select a random number.

Leave a Comment