1 |
/* RCSid $Id: random.h,v 2.23 2016/03/06 01:13:17 schorsch Exp $ */ |
2 |
/* |
3 |
* random.h - header file for random(3) and urand() function. |
4 |
*/ |
5 |
#ifndef _RAD_RANDOM_H_ |
6 |
#define _RAD_RANDOM_H_ |
7 |
|
8 |
#include <stdlib.h> |
9 |
|
10 |
#ifdef __cplusplus |
11 |
extern "C" { |
12 |
#endif |
13 |
|
14 |
#if defined(_WIN32) || defined(_WIN64) |
15 |
#if (RAND_MAX <= 65536) |
16 |
#define random() ((long)rand()<<16^(long)rand()<<6^(long)rand()>>4) |
17 |
#else |
18 |
#define random() rand() |
19 |
#endif |
20 |
#define srandom(s) srand((unsigned)(s)) |
21 |
|
22 |
#define frandom() (rand()*(1./(RAND_MAX+.5))) |
23 |
|
24 |
#else |
25 |
|
26 |
#define random() lrand48() |
27 |
#define srandom(s) srand48((long)(s)) |
28 |
#define frandom() drand48() |
29 |
|
30 |
#endif |
31 |
|
32 |
extern unsigned short *urperm; |
33 |
extern int urmask; |
34 |
|
35 |
#define urand(i) (urmask ? (urperm[(i)&urmask]+frandom())/(urmask+1.) \ |
36 |
: frandom()) |
37 |
|
38 |
/* defined in urand.c */ |
39 |
extern long irandom(long modulus); |
40 |
|
41 |
extern int initurand(int size); |
42 |
|
43 |
extern int ilhash(int *d, int n); |
44 |
|
45 |
extern int urind(int s, int i); |
46 |
/* defined in multisamp.c */ |
47 |
extern void multisamp(double t[], int n, double r); |
48 |
|
49 |
|
50 |
#ifdef __cplusplus |
51 |
} |
52 |
#endif |
53 |
#endif /* _RAD_RANDOM_H_ */ |
54 |
|