#include <stdlib.h>
#include <string.h>
#include <pthread.h>
-#include <time.h>
-#include <unistd.h>
static uint want_image_iface;
static uint want_threads;
else
die("Invalid parameter");
- srandom(time(NULL) ^ getpid());
+ random_gen_seed();
if (want_image_iface)
test_image_iface();
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
-#include <time.h>
-#include <sys/types.h>
-#include <unistd.h>
static void NONRET
usage(void)
file_name_2 = argv[optind++];
MSG("Initializing image library");
- srandom(time(NULL) ^ getpid());
+ random_gen_seed();
srgb_to_luv_init();
image_context_init(&ctx);
#define page_alloc_zero ucw_page_alloc_zero
#define page_free ucw_page_free
#define page_realloc ucw_page_realloc
+#define random_set_seed ucw_random_set_seed
+#define random_gen_seed ucw_random_gen_seed
#define random_max ucw_random_max
#define random_max_u64 ucw_random_max_u64
#define random_u32 ucw_random_u32
/*** === Random numbers (random-legacy.c) ***/
+void random_set_seed(uint seed); /** Initialize seed value for the legacy interface below. **/
+uint random_gen_seed(void); /** Combines fastrand_gen_seed_value() and random_set_seed(). **/
uint random_u32(void); /** Return a pseudorandom 32-bit number. **/
-uint random_max(uint max); /** Return a pseudorandom 32-bit number in range [0,@max). **/
+uint random_max(uint max); /** Return a pseudorandom 30-bit number in range [0,@max). **/
u64 random_u64(void); /** Return a pseudorandom 64-bit number. **/
u64 random_max_u64(u64 max); /** Return a pseudorandom 64-bit number in range [0,@max). **/
#include <ucw/getopt.h>
#include <stdio.h>
-#include <stdlib.h>
-#include <time.h>
static void
fill(byte *ptr, uint len, uint magic)
int main(int argc, char **argv)
{
- srand(time(NULL));
log_init(argv[0]);
cf_def_file = NULL;
if (cf_getopt(argc, argv, CF_SHORT_OPTS, CF_NO_LONG_OPTS, NULL) >= 0 || argc != optind)
die("Invalid usage");
+ random_gen_seed();
uint max = 1000, n = 0, m = 0, can_realloc = 0;
void *ptr[max];
struct mempool_state *state[max];
* UCW Library -- Unbiased Random Numbers
*
* (c) 1998--2006 Martin Mares <mj@ucw.cz>
+ * (c) 2020 Pavel Charvat <pchar@ucw.cz>
*
* This software may be freely distributed and used according to the terms
* of the GNU Lesser General Public License.
*/
#include <ucw/lib.h>
+#include <ucw/random.h>
#include <stdlib.h>
/* We expect the random generator in libc to give at least 30 bits of randomness */
COMPILE_ASSERT(RAND_MAX_RANGE_TEST, RAND_MAX >= (1 << 30)-1);
+void
+random_set_seed(uint seed)
+{
+ srandom(seed);
+}
+
+uint
+random_gen_seed(void)
+{
+ uint seed = fastrand_gen_seed_value();
+ random_set_seed(seed);
+ return seed;
+}
+
uint
random_u32(void)
{
uint avg_item_size = KEY4_MAX/2 + 4 + (mode ? 128 : 0);
uint N = MIN(size / avg_item_size, 0xffffffff);
msg(L_INFO, ">>> Strings %s(N=%u)", (mode ? "with data " : ""), N);
- srand(1);
+ random_set_seed(1);
struct key4 k, lastk;
byte buf[256], buf2[256];
#include <ucw/lib.h>
#include <ucw/getopt.h>
-#include <stdlib.h>
+#include <alloca.h>
#include <string.h>
-#include <time.h>
#define TRIE_PREFIX(x) basic_##x
#define TRIE_NODE_TYPE char
log_init(argv[0]);
if (cf_getopt(argc, argv, CF_SHORT_OPTS, CF_NO_LONG_OPTS, NULL) >= 0 || optind + 1 != argc)
die("Invalid usage, see the source code");
- srandom(time(NULL));
+ random_gen_seed();
char *test = argv[optind];
if (!strcmp(test, "basic"))