Generating Random Numbers in FORTRAN

Last reviewed: July 19, 1995
Article ID: Q27211
The information in this article applies to:
  • Microsoft FORTRAN for MS-DOS, versions 4.0, 4.01, 4.1, 5.0, 5.1

Microsoft FORTRAN provides a random number generator in versions 5.0, 5.01, and 5.1. It is documented on pages 272-273 of the Microsoft FORTRAN "Reference" manual for versions 5.0 and 5.1. Even though previous versions of Microsoft FORTRAN do not provide a random number generation function, there are at least two methods to generate random numbers in FORTRAN versions 4.0, 4.01, and 4.1.

The DEMORAN.FOR file demonstrates a uniform random-number generator for FORTRAN. DEMORAN.FOR is distributed on the Utilities and Source Code Disk (disk 3 or 6) in FORTRAN versions 4.0 and 4.01 and on the Setup disk for version 4.1. Comments at the beginning of the DEMORAN.FOR file provide documentation.

The other method involves using the mixed-language programming capabilities of Microsoft FORTRAN. Call a Microsoft C or QuickC run-time library to access the rand() function in the library routines.


Additional reference words: kbinf 4.00 4.01 4.10 5.00 5.10
KBCategory: kbprg
KBSubcategory: FORTLngIss


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: July 19, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.