Annotation of 43BSDReno/games/monop/roll.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1980 Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * Redistribution and use in source and binary forms are permitted
        !             6:  * provided that: (1) source distributions retain this entire copyright
        !             7:  * notice and comment, and (2) distributions including binaries display
        !             8:  * the following acknowledgement:  ``This product includes software
        !             9:  * developed by the University of California, Berkeley and its contributors''
        !            10:  * in the documentation or other materials provided with the distribution
        !            11:  * and in all advertising materials mentioning features or use of this
        !            12:  * software. Neither the name of the University nor the names of its
        !            13:  * contributors may be used to endorse or promote products derived
        !            14:  * from this software without specific prior written permission.
        !            15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
        !            16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
        !            17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            18:  */
        !            19: 
        !            20: #ifndef lint
        !            21: static char sccsid[] = "@(#)roll.c     5.5 (Berkeley) 6/1/90";
        !            22: #endif /* not lint */
        !            23: 
        !            24: /*
        !            25:  *     This routine rolls ndie nside-sided dice.
        !            26:  */
        !            27: 
        !            28: # define       reg     register
        !            29: 
        !            30: # if !defined(vax) && !defined(tahoe)
        !            31: # define       MAXRAND 32767L
        !            32: 
        !            33: roll(ndie, nsides)
        !            34: int    ndie, nsides; {
        !            35: 
        !            36:        reg long        tot;
        !            37:        reg unsigned    n, r;
        !            38: 
        !            39:        tot = 0;
        !            40:        n = ndie;
        !            41:        while (n--)
        !            42:                tot += rand();
        !            43:        return (int) ((tot * (long) nsides) / ((long) MAXRAND + 1)) + ndie;
        !            44: }
        !            45: 
        !            46: # else
        !            47: 
        !            48: roll(ndie, nsides)
        !            49: reg int        ndie, nsides; {
        !            50: 
        !            51:        reg int         tot, r;
        !            52:        reg double      num_sides;
        !            53: 
        !            54:        num_sides = nsides;
        !            55:        tot = 0;
        !            56:        while (ndie--)
        !            57:                tot += (r = rand()) * (num_sides / 017777777777) + 1;
        !            58:        return tot;
        !            59: }
        !            60: # endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.