1 | /* xscreensaver, Copyright (c) 1997, 1998, 2003 by Jamie Zawinski <jwz@jwz.org> |
---|
2 | * |
---|
3 | * Permission to use, copy, modify, distribute, and sell this software and its |
---|
4 | * documentation for any purpose is hereby granted without fee, provided that |
---|
5 | * the above copyright notice appear in all copies and that both that |
---|
6 | * copyright notice and this permission notice appear in supporting |
---|
7 | * documentation. No representations are made about the suitability of this |
---|
8 | * software for any purpose. It is provided "as is" without express or |
---|
9 | * implied warranty. |
---|
10 | */ |
---|
11 | |
---|
12 | #ifndef __YARANDOM_H__ |
---|
13 | #define __YARANDOM_H__ |
---|
14 | |
---|
15 | #undef random |
---|
16 | #undef rand |
---|
17 | #undef drand48 |
---|
18 | #undef srandom |
---|
19 | #undef srand |
---|
20 | #undef srand48 |
---|
21 | #undef frand |
---|
22 | #undef RAND_MAX |
---|
23 | |
---|
24 | #ifdef VMS |
---|
25 | # include "vms-gtod.h" |
---|
26 | #endif |
---|
27 | |
---|
28 | extern unsigned int ya_random (void); |
---|
29 | extern void ya_rand_init (unsigned int); |
---|
30 | |
---|
31 | #define random() ya_random() |
---|
32 | #define RAND_MAX 0xFFFFFFFF |
---|
33 | |
---|
34 | /*#define srandom(i) ya_rand_init(0)*/ |
---|
35 | |
---|
36 | /* Define these away to keep people from using the wrong APIs in xscreensaver. |
---|
37 | */ |
---|
38 | #define rand __ERROR_use_random_not_rand_in_xscreensaver__ |
---|
39 | #define drand48 __ERROR_use_frand_not_drand48_in_xscreensaver__ |
---|
40 | #define srandom __ERROR_do_not_call_srandom_in_xscreensaver__ |
---|
41 | #define srand __ERROR_do_not_call_srand_in_xscreensaver__ |
---|
42 | #define srand48 __ERROR_do_not_call_srand48_in_xscreensaver__ |
---|
43 | #define ya_rand_init __ERROR_do_not_call_ya_rand_init_in_xscreensaver__ |
---|
44 | |
---|
45 | |
---|
46 | #if defined (__GNUC__) && (__GNUC__ >= 2) |
---|
47 | /* Implement frand using GCC's statement-expression extension. */ |
---|
48 | |
---|
49 | # define frand(f) \ |
---|
50 | __extension__ \ |
---|
51 | ({ double tmp = ((((double) random()) * ((double) (f))) / \ |
---|
52 | ((double) ((unsigned int)~0))); \ |
---|
53 | tmp < 0 ? (-tmp) : tmp; }) |
---|
54 | |
---|
55 | #else /* not GCC2 - implement frand using a global variable.*/ |
---|
56 | |
---|
57 | static double _frand_tmp_; |
---|
58 | # define frand(f) \ |
---|
59 | (_frand_tmp_ = ((((double) random()) * ((double) (f))) / \ |
---|
60 | ((double) ((unsigned int)~0))), \ |
---|
61 | _frand_tmp_ < 0 ? (-_frand_tmp_) : _frand_tmp_) |
---|
62 | |
---|
63 | #endif /* not GCC2 */ |
---|
64 | |
---|
65 | #endif /* __YARANDOM_H__ */ |
---|