diff options
author | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2015-12-28 14:09:09 +0000 |
---|---|---|
committer | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2015-12-28 14:09:09 +0000 |
commit | 813b4d405bc2fa02cb6a1fa04ec8cb1aff22dd86 (patch) | |
tree | aea66425c7948209d6d027dd0459e4c9186f19b5 /Build/source/libs/poppler/poppler-src/goo/grandom.cc | |
parent | 5220b85007fbd61c7925bafba0bf06551e965e98 (diff) |
poppler-0.39.0
git-svn-id: svn://tug.org/texlive/trunk@39215 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/libs/poppler/poppler-src/goo/grandom.cc')
-rw-r--r-- | Build/source/libs/poppler/poppler-src/goo/grandom.cc | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/Build/source/libs/poppler/poppler-src/goo/grandom.cc b/Build/source/libs/poppler/poppler-src/goo/grandom.cc new file mode 100644 index 00000000000..1237175420b --- /dev/null +++ b/Build/source/libs/poppler/poppler-src/goo/grandom.cc @@ -0,0 +1,70 @@ +/* + * grandom.cc + * + * This file is licensed under the GPLv2 or later + * + * Pseudo-random number generation + * + * Copyright (C) 2012 Fabio D'Urso <fabiodurso@hotmail.it> + */ + +#include <config.h> +#include "grandom.h" +#include "gtypes.h" + +#ifdef HAVE_RAND_R // rand_r backend (POSIX) + +static GBool initialized = gFalse; + +#include <stdlib.h> +#include <time.h> +static unsigned int seed; + +static void initialize() { + if (!initialized) { + seed = time(NULL); + initialized = gTrue; + } +} + +void grandom_fill(Guchar *buff, int size) +{ + initialize(); + while (size--) + *buff++ = rand_r(&seed) % 256; +} + +double grandom_double() +{ + initialize(); + return rand_r(&seed) / (1 + (double)RAND_MAX); +} + +#else // srand+rand backend (unsafe, because it may interfere with the application) + +static GBool initialized = gFalse; + +#include <stdlib.h> +#include <time.h> + +static void initialize() { + if (!initialized) { + srand(time(NULL)); + initialized = gTrue; + } +} + +void grandom_fill(Guchar *buff, int size) +{ + initialize(); + while (size--) + *buff++ = rand() % 256; +} + +double grandom_double() +{ + initialize(); + return rand() / (1 + (double)RAND_MAX); +} + +#endif |