4 * This file is licensed under the GPLv2 or later
6 * Pseudo-random number generation
8 * Copyright (C) 2012 Fabio D'Urso <fabiodurso@hotmail.it>
15 #ifdef HAVE_RAND_R // rand_r backend (POSIX)
17 static GBool initialized
= gFalse
;
21 static unsigned int seed
;
23 static void initialize() {
30 void grandom_fill(Guchar
*buff
, int size
)
34 *buff
++ = rand_r(&seed
) % 256;
37 double grandom_double()
40 return rand_r(&seed
) / (1 + (double)RAND_MAX
);
43 #else // srand+rand backend (unsafe, because it may interfere with the application)
45 static GBool initialized
= gFalse
;
50 static void initialize() {
57 void grandom_fill(Guchar
*buff
, int size
)
61 *buff
++ = rand() % 256;
64 double grandom_double()
67 return rand() / (1 + (double)RAND_MAX
);