1 |
– |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Anticorrelated random function due to Christophe Schlick |
6 |
|
*/ |
7 |
|
|
8 |
+ |
#include "copyright.h" |
9 |
+ |
|
10 |
+ |
#include <stdlib.h> |
11 |
|
#include "random.h" |
12 |
|
|
13 |
< |
#define NULL 0 |
13 |
> |
#undef initurand |
14 |
|
|
15 |
< |
extern char *malloc(); |
15 |
> |
#define MAXORDER (8*sizeof(unsigned short)) |
16 |
|
|
17 |
< |
short *urperm = NULL; /* urand() permutation */ |
17 |
> |
unsigned short *urperm = NULL; /* urand() permutation */ |
18 |
|
int urmask; /* bits used in permutation */ |
19 |
|
|
20 |
– |
|
20 |
|
int |
21 |
|
initurand(size) /* initialize urand() for size entries */ |
22 |
|
int size; |
25 |
|
register int i, offset; |
26 |
|
|
27 |
|
if (urperm != NULL) |
28 |
< |
free((char *)urperm); |
29 |
< |
size--; |
28 |
> |
free((void *)urperm); |
29 |
> |
if (--size <= 0) { |
30 |
> |
urperm = NULL; |
31 |
> |
urmask = 0; |
32 |
> |
return(0); |
33 |
> |
} |
34 |
|
for (i = 1; size >>= 1; i++) |
35 |
|
; |
36 |
< |
order = i; |
36 |
> |
order = i>MAXORDER ? MAXORDER : i; |
37 |
|
urmask = (1<<i) - 1; |
38 |
< |
urperm = (short *)malloc((urmask+1)*sizeof(short)); |
38 |
> |
urperm = (unsigned short *)malloc((urmask+1)*sizeof(unsigned short)); |
39 |
|
if (urperm == NULL) { |
40 |
|
eputs("out of memory in initurand\n"); |
41 |
|
quit(1); |