XL: Using RAND() to Generate Randomly Distributed Integers

Last reviewed: February 2, 1998
Article ID: Q96746

The information in this article applies to:
  • Microsoft Excel for Windows, versions 2.x, 3.x, 4.x, 5.0, 5.0c
  • Microsoft Excel for Windows NT, version 5.0
  • Microsoft Excel for Windows 95, version 7.0
  • Microsoft Excel 97 for Windows
  • Microsoft Excel for the Macintosh, versions 2.x, 3.0, 4.0, 5.0
  • Microsoft Excel 98 Macintosh Edition

SUMMARY

Microsoft Excel does not include a built-in method for generating sets of randomly sorted, uniformly distributed integers. The information in this article describes how you can use the RAND function (which is integral to Microsoft Excel) to create a set of this kind.

MORE INFORMATION

Below is an example of a set of randomly sorted, uniformly distributed integers from 1 to 10:

   10   5   7   4   8   1   6   2   3   9

The set is said to be uniformly distributed because every value in the range occurs exactly once.

To generate such a set of randomly sorted, uniformly distributed integers, follow these steps:

  1. In a new worksheet, enter the following formulas:

           A1: =RAND()       B1:   1
           A2: =RAND()       B2:   2
           A3: =RAND()       B3:   3
           A4: =RAND()       B4:   4
           A5: =RAND()       B5:   5
           A6: =RAND()       B6:   6
           A7: =RAND()       B7:   7
           A8: =RAND()       B8:   8
           A9: =RAND()       B9:   9
          A10: =RAND()       B10: 10
    
    

  2. Select the range A1:B10.

  3. On the Data menu, click Sort.

  4. In the 1st Key box, enter A1 and click OK to sort the range.

After the sort is complete, cells B1:B10 contain a set of randomly sorted, uniformly distributed integers that range from 1 to 10. Each time the range is sorted, the integers in B1:B10 are resorted randomly, which results in a new set.

REFERENCES

"Microsoft Excel Function Reference," version 4.0, page 344 "Microsoft Excel Function Reference," version 3.0, page 191 "Microsoft Excel Functions and Macros," version 2.1 for Windows, page 396


Additional query words: 2.0 2.00 2.01 2.1 2.10 2.2 2.20 2.21 3.0 3.00
4.0 4.00 4.0a 4.00a 5.0 5.00a 5.00c 7.00 8.00 97 98 XL98 XL97 XL7 XL5 XL4
XL3 randbetween analysis toolpak toolpack tool pak pack pick hat numbers
out unique random numbers
Keywords : xlformula
Version : WINDOWS:2.0,3.0,4.0,5.0,5.0c,7.0,97; MACINTOSH:2.0,3.0,4.0,5.0,98
Platform : MACINTOSH OS/2 WINDOWS
Issue type : kbinfo


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 2, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.