Back to index

kdeartwork  4.3.2
xs_yarandom.h
Go to the documentation of this file.
00001 /* xscreensaver, Copyright (c) 1997 by Jamie Zawinski <jwz@jwz.org>
00002  *
00003  * Permission to use, copy, modify, distribute, and sell this software and its
00004  * documentation for any purpose is hereby granted without fee, provided that
00005  * the above copyright notice appear in all copies and that both that
00006  * copyright notice and this permission notice appear in supporting
00007  * documentation.  No representations are made about the suitability of this
00008  * software for any purpose.  It is provided "as is" without express or 
00009  * implied warranty.
00010  */
00011 
00012 #ifndef __YARANDOM_H__
00013 #define __YARANDOM_H__
00014 
00015 #undef random
00016 #undef rand
00017 #undef drand48
00018 #undef srandom
00019 #undef srand
00020 #undef srand48
00021 #undef frand
00022 
00023 #ifdef VMS
00024 # include "vms-gtod.h"
00025 #endif
00026 
00027 /* #define random()   ya_random()
00028  #define srandom(i) ya_rand_init(0) */
00029 
00030 extern unsigned int ya_random (void);
00031 extern void ya_rand_init (unsigned int);
00032 
00033 
00034 #if defined (__GNUC__) && (__GNUC__ >= 2)
00035  /* Implement frand using GCC's statement-expression extension. */
00036 
00037 # define frand(f)                                              \
00038   ({ double tmp = (((double) random()) /                       \
00039                  (((double) ((unsigned int)~0)) / ((double) (f))));   \
00040      tmp < 0 ? (-tmp) : tmp; })
00041 
00042 #else /* not GCC2 - implement frand using a global variable.*/
00043 
00044 static double _frand_tmp_;
00045 # define frand(f)                                              \
00046   (_frand_tmp_ = (((double) random()) /                        \
00047                 (((double) ((unsigned int)~0)) / ((double) (f)))),    \
00048    _frand_tmp_ < 0 ? (-_frand_tmp_) : _frand_tmp_)
00049 
00050 #endif /* not GCC2 */
00051 
00052 #endif /* __YARANDOM_H__ */