The RAND function returns a random real number, greater than or equal to 0 and less than and equal to 1

The RAND () function returns a random real number, greater than or equal to 0 and less than and equal to 1.

In the process of working with Excel spreadsheets, there will be many cases where you need to get a random number, a character in a certain range. You may have heard of the RAND () function, but you do not know the syntax and how to use the function. The following article will describe the syntax and usage of the RAND () function, please follow along!

The RAND function returns a random real number, greater than or equal to 0 and less than and equal to 1 Picture 1The RAND function returns a random real number, greater than or equal to 0 and less than and equal to 1 Picture 1

Description

The RAND () function returns a random real number, greater than or equal to 0 and less than and equal to 1.

Syntax

= RAND ()

Function without parameters.

The RAND () function can also help you get a random number between any two values.

- To get a random number greater than or equal to 0 and less than n, you use the syntax.

= RAND () * n

- To get a random number greater than or equal to m and less than n, you use the syntax.

= RAND () * (n - m) + m

Note

- The RAND () function is a modified function, so the results of the RAND () function will change when you update or reopen the spreadsheet.

- If you want the results to not change, you do the following: when you have finished entering the RAND () function, press F9 and then press Enter. This will take a random number at the time of entering the function and then always use that number.

For example

Example 1: Use the RAND () function to get a random number.

The RAND function returns a random real number, greater than or equal to 0 and less than and equal to 1 Picture 2The RAND function returns a random real number, greater than or equal to 0 and less than and equal to 1 Picture 2

Example 2: Take a positive integer random number, including x digits.

You use the formula to get random numbers in the range:

= RAND () * (n - m) + m

To get random numbers that fix the number of digits, you would set n = 10 ^ x and m = 10 ^ (x-1) where x is the number of digits you want.

Then you use the INT () function to get positive integers of the RAND () function.

= INT (RAND () * (n - m) + m)

For example, take a random positive integer, consisting of 5 digits

The RAND function returns a random real number, greater than or equal to 0 and less than and equal to 1 Picture 3The RAND function returns a random real number, greater than or equal to 0 and less than and equal to 1 Picture 3

Example 3: Get a random character.

The RAND () function, in addition to giving a random number, may also return a random character.

For example take a random character in the English alphabet.

The English alphabet has 26 letters so first you need to get a random integer between 1 and 26.

= INT (RAND () * 26 + 1)

According to ANSI encoding, uppercase characters (A to Z) range from ANSI 65 code to ANSI 90 code. Next use the CHAR () function to return the result as characters.

= CHAR (INT (RAND () * 26 + 1) + 64)

The RAND function returns a random real number, greater than or equal to 0 and less than and equal to 1 Picture 4The RAND function returns a random real number, greater than or equal to 0 and less than and equal to 1 Picture 4

Similar to the random lowercase characters (a to z) from ANSI 97 to ANSI 122, use the CHAR () function to return the result as a character.

= CHAR (INT (RAND () * 26 + 1) + 96)

The RAND function returns a random real number, greater than or equal to 0 and less than and equal to 1 Picture 5The RAND function returns a random real number, greater than or equal to 0 and less than and equal to 1 Picture 5

Thus, the article has guided you very detailed about the RAND () function and how to use the RAND () function through specific examples. Hopefully after this article, all of you can use the RAND () function as needed. Good luck!

5 ★ | 1 Vote