| 7 |
|
|
| 8 |
|
#include "copyright.h" |
| 9 |
|
|
| 10 |
< |
#include "standard.h" |
| 10 |
> |
#include "rterror.h" |
| 11 |
|
#include "random.h" |
| 12 |
|
|
| 13 |
|
#undef initurand |
| 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( /* initialize urand() for size entries */ |