wmappkill: Add version 0.2 to repository.
[dockapps.git] / wmMatrix / yarandom.h
blobfcdaa9216e452516727d67b6cc48e71cfe2f48b6
1 /* xscreensaver, Copyright (c) 1997, 1998 by Jamie Zawinski <jwz@jwz.org>
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.
12 #ifndef __YARANDOM_H__
13 #define __YARANDOM_H__
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
24 #ifdef VMS
25 #include "vms-gtod.h"
26 #endif
28 #define random() ya_random()
29 #define srandom(i) ya_rand_init(0)
30 #define RAND_MAX 0x7FFFFFFF
32 extern unsigned int ya_random(void);
33 extern void ya_rand_init(unsigned int);
35 #if defined (__GNUC__) && (__GNUC__ >= 2)
36 /* Implement frand using GCC's statement-expression extension. */
38 #define frand(f) \
39 ({ double tmp = (((double) random()) / \
40 (((double) ((unsigned int)~0)) / ((double) (f)))); \
41 tmp < 0 ? (-tmp) : tmp; })
43 #else /* not GCC2 - implement frand using a global variable. */
45 static double _frand_tmp_;
46 #define frand(f) \
47 (_frand_tmp_ = (((double) random()) / \
48 (((double) ((unsigned int)~0)) / ((double) (f)))), \
49 _frand_tmp_ < 0 ? (-_frand_tmp_) : _frand_tmp_)
51 #endif /* not GCC2 */
53 #endif /* __YARANDOM_H__ */