home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************
- * *
- * Copyright (c) 1988, David B. Wecker *
- * All Rights Reserved *
- * *
- * This file is part of DBW_uRAY *
- * *
- * DBW_uRAY is distributed in the hope that it will be useful, but *
- * WITHOUT ANY WARRANTY. No author or distributor accepts *
- * responsibility to anyone for the consequences of using it or for *
- * whether it serves any particular purpose or works at all, unless *
- * he says so in writing. Refer to the DBW_uRAY General Public *
- * License for full details. *
- * *
- * Everyone is granted permission to copy, modify and redistribute *
- * DBW_uRAY, but only under the conditions described in the *
- * DBW_uRAY General Public License. A copy of this license is *
- * supposed to have been given to you along with DBW_uRAY so you *
- * can know your rights and responsibilities. It should be in a file *
- * named COPYING. Among other things, the copyright notice and this *
- * notice must be preserved on all copies. *
- ************************************************************************
- * *
- * Authors: *
- * DBW - David B. Wecker *
- * *
- * Versions: *
- * V1.0 881023 DBW - First released version *
- * V1.1 881110 DBW - Fixed scan coherence code *
- * V1.2 881125 DBW - Removed ALL scan coherence code (useless) *
- * added "fat" extent boxes *
- * *
- ************************************************************************/
-
- #include "uray.h"
-
- /************************************************************************/
- /************ random number generator (see uray.h for random table ******/
- /************************************************************************/
-
- /*
- * srandom(x) - sets a random seed starting point (long int)
- * random() - returns next random long int (between 0 and 0x7FFFFFFF)
- * rnd() - return next random FLTDBL (between 0 and 1)
- */
-
- srandom( x )
- unsigned x;
- {
- register int i;
-
- /* rebuild the random table */
- randtbl[ 0 ] = x;
- for( i = 1; i < 63; i++ )
- randtbl[i] = 1103515245*randtbl[i - 1] + 12345;
-
- fptr = &randtbl[ 1 ];
- rptr = &randtbl[ 0 ];
- }
-
- long random()
- {
- long i;
-
- *fptr += *rptr;
- i = (*fptr >> 1)&0x7fffffff; /* chucking least random bit */
- if( ++fptr >= end_ptr ) {
- fptr = randtbl;
- ++rptr;
- }
- else if( ++rptr >= end_ptr ) rptr = randtbl;
- return( i );
- }
-
- FLTDBL rnd() {
- return ((FLTDBL)random()) / 2147483647.0;
- }
-
-