5 Ways To Generate Random Numbers On Your Mac

Learn how to get random numbers on your Mac using the Calculator app, the Numbers app, Siri, the Terminal and a custom Shortcut.
You can also watch this video at YouTube.
Watch more videos about related subjects: Numbers (200 videos), Siri (27 videos), Terminal (43 videos).

Video Transcript

Hi, this is Gary with MacMost.com. Let me show you 5 different ways that you could easily generate random numbers on your Mac.
MacMost is brought to you thanks to a great group of more than 1000 supporters. Go to MacMost.com/patreon. There you could read more about the Patreon Campaign. Join us and get exclusive content and course discounts.
So if you need to generate a random number on your Mac very quickly there are several different ways to do it. Let's start off with the Calculator App. This app built into your Mac doesn't seem to have any random number function here but if you go to View, and then switch to Scientific Calculator then there's a Rand button right here. If you click it you get a random number between zero and 1. So if you need to have something more specific, like say between 1 and 6, then what you would do is generate the random number, multiply by that number say 6, and then of course you have to add 1 because technically this is between zero and 5. So in this case it would be 4, or I could just add one like that and see the four there. 
Now, of course, you can use the Mac Spreadsheet App in Numbers to do this. You could also use another spreadsheet app if you like. The way to do it here in Numbers is use one of two functions. So if I use the Rand function I actually get a random number between zero and 1 just like with calculator. But what's more useful is using the Rand Between function and this gives you two parameters. The lower and upper limits. So I can do 1 to 6 and I get a random number between 1 and 6. Now anytime I change something in the spreadsheet it regenerates this. So if I were to put just a number here like zero notice how it changes there. An easy way to do this is to put a checkbox cell. So I'm going to select that cell, go to Cell, Data Format, Change to Checkbox and now I have a checkbox here. If I check it or uncheck it, it will force the random numbers to regenerate. If I need many Rand numbers I can Copy and say Paste this into many cells and then anytime I check this you could see it regenerates all of them. 
If I ever want to generate them and then have them stay the same no matter what I change you could always select all those cells, go to Copy and then go back to Edit and go to Paste Formula results. This changes it from a formula to the actual number. So this is actually a 4,1,1,5 etc no matter how many times I change other cells these numbers are permanent now. 
Now perhaps the easiest way to generate a Rand number is use Siri. I'll activate Siri here. You can use the keyboard shortcut or speak to activate it, Give me a random number. The answer is 41. So you can see how it generates a random number between zero and 100 when you ask it this way. But you could also ask for a specific range. Give me a random number between 1 and 6. The answer is 1. Another cool thing you can do with Siri is just have it flip a coin for you. Flip a coin. Ten. 
Now as you can imagine you can use Terminal to do this. There are a couple ways. If you are an experience Terminal user you may know that there is a random function that you can use, like this. Echo will just print out the result of this. So $RANDOM will give me a value. It turns out it is between zero and 32767. So if you wanted it to be between something more specific, like say 1 and 6, you could do echo and then you need double parentheses here and you could do $((RANDOM and then divide by this number and this will give you zero all the time because it's always going to round down. But if I were to then multiply by the range I wanted, so multiply by 6 that would then give me a number between zero and 5 plus 1, like that, now gives me a number between one and six. So I can hit return and get 3. I can, of course, easily repeat a command in Terminal with Up Arrow to bring up the last command. Return to try again. So I can keep going.
I think a better way to do it in Terminal is to use the jot command. Jot command with dash r for random will give you a random number and you can say how many numbers you want. So 1. Let's say between 1 and 6. So I get 3 and I can keep doing that. But I could also change this and it will give me ten numbers now between 1 and 6. Of course now you can easily Copy and Paste this somewhere if you need it. 
So finally let's create a shortcut in the Shortcut App to do this. So I'll create a new one here and I'll Search for Random. Of course I will come up with Random Number. I'll drag that over here. Random Number between 1 and 6. I could actually run it here in Shortcuts and it will show the results here. Let's give it a name. There's even a very appropriate icon for this right here. Let's output it. We could use QuickLook to output the results. But instead let's choose Alert. That's a little bit more compact. Drop it here.  I will erase what's in here and Control click it to insert variable. Select variable. Select the result of this. Now you can see it is linked together. So now when I run it, it will show the results here. I could also, if I wanted, instead of show Alert I could use Copy to Clipboard to just run it and get that random number in the clipboard. 
Let's go to Settings here. I'll say Pin in Menu Bar so now I can run it from here anytime I want. I could also say Add Keyboard Shortcut. Now let's do Shift Option Command R. You could see that's automatically going to add it to the Services Menu. So if I look under Services here I'll see it. I'll run it the first time this way. I find once you do that that it usually works as a keyboard shortcut. So anytime I want I just use that keyboard shortcut and I get a random number. 
So there's a bunch of different ways you could do it. As you can see you can highly customize the range that the numbers use. You can even build a shortcut to ask you for the lower and higher end of that range and put that into the random function or you can even have it just have you select from a menu. Say for using die a different number of sides, like 4, 6, 8, and 12 or 20. I hope you found this useful Thanks for watching.

Comments: 7 Comments

    Ken
    3 years ago

    I do like the shortcut idea. Is there way to have to die roll. One being 1-6 and the other the same. Thanks. Ken

    3 years ago

    Ken: In Shortcuts, yes. Have the random number generated twice, then use a "Text" action to concatenate them both. Or a "Calculate" action to add them both and give the result.

    Karl
    3 years ago

    Are you able to exclude numbers within the given range? Example: a sign up sheet for a drawing, where people choose their numbers and once all have signed up there are unselected numbers within the range of possible choices.

    3 years ago

    Karl: In that case you would just have all of the numbers in a column, and chose a random row. So if 20 people chose numbers, then they would be rows 1-20. Choose a random number between 1-20 and there is your winner.

    Marc Chamberland
    3 years ago

    Hi Gary. As always your videos are always very interesting and easy to understand.
    Let's suppose i use the random formula in Numbers to select a number between 1 and 50, and i need 6 numbers in that range, how can i be sure that the same random number doesn't come twice ? ex : 23-(16)-14-50-49-(16) And is there a way to get them sorted ??

    3 years ago

    Marc: Lots of ways to do it. The simplest is to just generate more numbers than you need and take the first 6 unique ones. Since you only need 6 numbers, this will be the easiest and quickest way to do it. Then delete the rest and sort.
    Or, you could put the numbers 1 through 50 in 50 rows of a table. Then in the next column put a RAND() function (random number between 0 and 1). Then sort by that second column. This is a "shuffle" like you are shuffling a deck of cards, or pulling bingo balls out of a box. Then delete that second column, delete the other 44 rows, and sort the remaining 6.

    Marc Chamberland
    3 years ago

    Thanks a lot. I will do so.

Comments are closed for this post.