| 7 |
|
|
| 8 |
|
#include "copyright.h" |
| 9 |
|
|
| 10 |
< |
#include <stdlib.h> |
| 11 |
< |
|
| 12 |
< |
#include "standard.h" |
| 10 |
> |
#include "rterror.h" |
| 11 |
|
#include "random.h" |
| 12 |
|
|
| 13 |
|
#undef initurand |
| 14 |
|
|
| 15 |
|
#define MAXORDER (8*sizeof(unsigned short)) |
| 16 |
|
|
| 17 |
< |
unsigned short *urperm = NULL; /* urand() permutation */ |
| 20 |
< |
int urmask; /* bits used in permutation */ |
| 17 |
> |
static unsigned short empty_tab = 0; |
| 18 |
|
|
| 19 |
+ |
unsigned short *urperm = &empty_tab; /* urand() permutation */ |
| 20 |
+ |
int urmask = 0; /* bits used in permutation */ |
| 21 |
+ |
|
| 22 |
+ |
|
| 23 |
+ |
long |
| 24 |
+ |
irandom( /* better than using random() % modulus */ |
| 25 |
+ |
long modulus |
| 26 |
+ |
) |
| 27 |
+ |
{ |
| 28 |
+ |
static const int isize = sizeof(int); |
| 29 |
+ |
static const int lsize = sizeof(long); |
| 30 |
+ |
static const int llsize = sizeof(long long); |
| 31 |
+ |
|
| 32 |
+ |
if ((lsize == 8) | (isize == 8)) |
| 33 |
+ |
return((random()*modulus)>>31); |
| 34 |
+ |
|
| 35 |
+ |
if (llsize == 8) |
| 36 |
+ |
return((random()*(long long)modulus)>>31); |
| 37 |
+ |
|
| 38 |
+ |
return(random() % modulus); |
| 39 |
+ |
} |
| 40 |
+ |
|
| 41 |
|
int |
| 42 |
< |
initurand(size) /* initialize urand() for size entries */ |
| 43 |
< |
int size; |
| 42 |
> |
initurand( /* initialize urand() for size entries */ |
| 43 |
> |
int size |
| 44 |
> |
) |
| 45 |
|
{ |
| 46 |
|
int order, n; |
| 47 |
< |
register int i, offset; |
| 47 |
> |
int i, offset; |
| 48 |
|
|
| 49 |
< |
if (urperm != NULL) |
| 49 |
> |
if ((urperm != NULL) & (urperm != &empty_tab)) |
| 50 |
|
free((void *)urperm); |
| 51 |
|
if (--size <= 0) { |
| 52 |
< |
urperm = NULL; |
| 52 |
> |
empty_tab = 0; |
| 53 |
> |
urperm = &empty_tab; |
| 54 |
|
urmask = 0; |
| 55 |
|
return(0); |
| 56 |
|
} |
| 78 |
|
|
| 79 |
|
|
| 80 |
|
int |
| 81 |
< |
ilhash(d, n) /* hash a set of integer values */ |
| 82 |
< |
register int *d; |
| 83 |
< |
register int n; |
| 81 |
> |
ilhash( /* hash a set of integer values */ |
| 82 |
> |
int *d, |
| 83 |
> |
int n |
| 84 |
> |
) |
| 85 |
|
{ |
| 86 |
< |
static int tab[8] = {13623,353,1637,5831,2314,3887,5832,8737}; |
| 87 |
< |
register int hval; |
| 86 |
> |
static int tab[8] = {103699,96289,73771,65203,81119,87037,92051,98899}; |
| 87 |
> |
int hval; |
| 88 |
|
|
| 89 |
|
hval = 0; |
| 90 |
|
while (n-- > 0) |
| 91 |
< |
hval += *d++ * tab[n&7]; |
| 92 |
< |
return(hval); |
| 91 |
> |
hval ^= *d++ * tab[n&7]; |
| 92 |
> |
return(hval & 0x7fffffff); |
| 93 |
|
} |