Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ rand(3C) — DG/UX 4.00

Media Vault

Software Library

Restoration Projects

Artifacts Sought



                                                                 rand(3C)



        _________________________________________________________________
        rand                                                     function
        Generate and return a random number in the range 0 to 32767.
        _________________________________________________________________


        Calling Sequence

        int rand(), m;
        m = rand();


        Description

        The rand function generates and returns a random number.  To be
        compatible with other C implementations, rand returns a number in
        the range 0 to 32767.  The seed (number from which random number
        generation begins) is +1, unless you change it with the srand
        function.

        The include file math.h defines this entry.


        Returns

        The rand function returns the random number it generates.


        Related Functions

        See also the dg_rand and srand functions.


        Example

        /* Program test for the rand() function */

        #include <math.h>

        int  result, i, c;

        main(argc, argv)

        int    argc;
        char  *argv[];
        {
            c = atoi(argv[1]);
            printf("List of %d random numbers:\n\n", c);
            for (i = 1; i<=c; i++)
                printf("%d\n", result = rand());
        }



        DG/UX 4.00                                                 Page 1
               Licensed material--property of copyright holder(s)





                                                                 rand(3C)



        A call to the program test with the number 4 generates the output

        List of 4 random numbers:

        30819
        12099
        10924
        22643

        These numbers will vary.












































        DG/UX 4.00                                                 Page 2
               Licensed material--property of copyright holder(s)



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026