33 |
|
urmask = 0; |
34 |
|
return(0); |
35 |
|
} |
36 |
< |
for (i = 1; size >>= 1; i++) |
37 |
< |
; |
38 |
< |
order = i>MAXORDER ? MAXORDER : i; |
39 |
< |
urmask = (1<<i) - 1; |
36 |
> |
for (i = 1; (size >>= 1); i++) |
37 |
> |
if (i == MAXORDER) |
38 |
> |
break; |
39 |
> |
order = i; |
40 |
> |
urmask = (1<<order) - 1; |
41 |
|
urperm = (unsigned short *)malloc((urmask+1)*sizeof(unsigned short)); |
42 |
|
if (urperm == NULL) { |
43 |
|
eputs("out of memory in initurand\n"); |
44 |
|
quit(1); |
45 |
|
} |
46 |
< |
urperm[0] = 0; |
46 |
> |
urperm[0] = (random() & 0x4000) != 0; |
47 |
|
for (n = 1, offset = 1; n <= order; n++, offset <<= 1) |
48 |
|
for (i = offset; i--; ) { |
49 |
< |
urperm[i] = |
49 |
< |
urperm[i+offset] = 2*urperm[i]; |
49 |
> |
urperm[i+offset] = urperm[i] <<= 1; |
50 |
|
if (random() & 0x4000) |
51 |
|
urperm[i]++; |
52 |
|
else |
53 |
|
urperm[i+offset]++; |
54 |
|
} |
55 |
< |
return(1<<order); |
55 |
> |
return(urmask+1); |
56 |
|
} |
57 |
|
|
58 |
|
|