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.