singularize srand in eina_init - only once in one place

simplify down to having a single srand() in eina_init and use urandom
if it works and is there - if not, time(NULL) will do. it's the best
we can...
This commit is contained in:
Carsten Haitzler 2020-10-03 20:46:50 +01:00
parent de5ac32870
commit 42c123d1d7
21 changed files with 22 additions and 75 deletions

View File

@ -67,8 +67,6 @@ eina_bench_array_4evas_render_inline(int request)
unsigned int i;
unsigned int j;
srand(time(NULL));
eina_init();
array = eina_array_new(64);
@ -133,8 +131,6 @@ eina_bench_array_4evas_render_iterator(int request)
unsigned int i;
unsigned int j;
srand(time(NULL));
eina_init();
array = eina_array_new(64);

View File

@ -38,8 +38,6 @@ eina_bench_convert_itoa_10(int request)
char tmp[128];
int i;
srand(time(NULL));
for (i = 0; i < request; ++i)
{
eina_convert_itoa(rand(), tmp);
@ -52,8 +50,6 @@ eina_bench_convert_itoa_16(int request)
char tmp[128];
int i;
srand(time(NULL));
for (i = 0; i < request; ++i)
{
eina_convert_xtoa(rand(), tmp);
@ -66,8 +62,6 @@ eina_bench_convert_snprintf_10(int request)
char tmp[128];
int i;
srand(time(NULL));
for (i = 0; i < request; ++i)
{
snprintf(tmp, 128, "%i", rand());
@ -80,8 +74,6 @@ eina_bench_convert_snprintf_x(int request)
char tmp[128];
int i;
srand(time(NULL));
for (i = 0; i < request; ++i)
{
snprintf(tmp, 128, "%x", rand());
@ -95,8 +87,6 @@ eina_bench_convert_snprintf_a(int request)
double r;
int i;
srand(time(NULL));
for (i = 0; i < request; ++i)
{
r = 10000 * (rand() / ((double)RAND_MAX + 1));
@ -114,8 +104,6 @@ eina_bench_convert_dtoa(int request)
double r;
int i;
srand(time(NULL));
for (i = 0; i < request; ++i)
{
r = 10000 * (rand() / ((double)RAND_MAX + 1));
@ -133,8 +121,6 @@ eina_bench_convert_gstrtod(int request)
double r;
int i;
srand(time(NULL));
for (i = 0; i < request; ++i)
{
r = 10000 * (rand() / ((double)RAND_MAX + 1));

View File

@ -50,8 +50,6 @@ eina_bench_sort_eina(int request)
eina_init();
srand(time(NULL));
for (i = 0; i < request; ++i)
{
char buffer[10];
@ -78,8 +76,6 @@ eina_bench_sort_evas(int request)
Evas_List *list = NULL;
int i;
srand(time(NULL));
for (i = 0; i < request; ++i)
{
char buffer[10];
@ -105,8 +101,6 @@ eina_bench_sort_glist(int request)
GList *list = NULL;
int i;
srand(time(NULL));
for (i = 0; i < request; ++i)
{
char buffer[10];

View File

@ -53,8 +53,6 @@ eina_bench_stringshare_job(int request)
tmp = eina_stringshare_add(build);
}
srand(time(NULL));
for (j = 0; j < 200; ++j)
for (i = 0; i < request; ++i)
{
@ -87,8 +85,6 @@ eina_bench_stringchunk_job(int request)
g_string_chunk_insert_const(chunk, build);
}
srand(time(NULL));
for (j = 0; j < 200; ++j)
for (i = 0; i < request; ++i)
{
@ -117,8 +113,6 @@ eina_bench_evas_job(int request)
tmp = evas_stringshare_add(build);
}
srand(time(NULL));
for (j = 0; j < 200; ++j)
for (i = 0; i < request; ++i)
{
@ -149,8 +143,6 @@ eina_bench_ecore_job(int request)
//tmp = ecore_string_instance(build);
}
srand(time(NULL));
for (j = 0; j < 200; ++j)
for (i = 0; i < request; ++i)
{

View File

@ -256,7 +256,6 @@ _edje_multisense_encode_to_ogg_vorbis(char *snd_path, double quality, SF_INFO sf
vorbis_analysis_init(&vd, &vi);
vorbis_block_init(&vd, &vb);
srand(time(NULL));
ogg_stream_init(&os, rand());
ogg_packet header;

View File

@ -1096,8 +1096,6 @@ test_map(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info
evas_object_event_callback_add(map, EVAS_CALLBACK_DEL, _del_map, NULL);
srand(time(NULL));
tile_srcs = elm_map_sources_get(map, ELM_MAP_SOURCE_TYPE_TILE);
route_srcs = elm_map_sources_get(map, ELM_MAP_SOURCE_TYPE_ROUTE);
name_srcs = elm_map_sources_get(map, ELM_MAP_SOURCE_TYPE_NAME);

View File

@ -154,7 +154,6 @@ main(int argc EINA_UNUSED, char *argv[] EINA_UNUSED)
Ecore_Timer *t;
const char *driver;
srand(time(NULL));
if (!ecore_evas_init())
{
fprintf(stderr, "Could not init the Ecore Evas\n");

View File

@ -85,7 +85,6 @@ int main(int argc, char **argv)
eina_init();
value_init();
srand(time(NULL));
v1 = eina_value_struct_new(V1_DESC);
v2 = eina_value_struct_new(V2_DESC);

View File

@ -418,8 +418,6 @@ elm_main(int argc EINA_UNUSED,
Eina_Bool bounce;
double h, v;
srand(time(NULL));
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
elm_app_info_set(elm_main, "elementary", "images");

View File

@ -317,8 +317,6 @@ main(void)
Evas_Object *last, *o;
int i;
srand(time(NULL));
if (!ecore_evas_init())
return EXIT_FAILURE;

View File

@ -226,8 +226,6 @@ main(void)
unsigned int pixels[(WIDTH / 4) * (HEIGHT / 4)];
Evas_Textblock_Style *st;
srand(time(NULL));
if (!ecore_evas_init())
return EXIT_FAILURE;

View File

@ -678,8 +678,6 @@ main(void)
unsigned int count;
Eina_Bool ret;
srand(time(NULL));
if (!ecore_evas_init())
return EXIT_FAILURE;

View File

@ -648,8 +648,6 @@ main(void)
unsigned int count;
Eina_Bool ret;
srand(time(NULL));
if (!ecore_evas_init())
return EXIT_FAILURE;

View File

@ -39,8 +39,6 @@ edje_init(void)
if (++_edje_init_count != 1)
return _edje_init_count;
srand(time(NULL));
EINA_SAFETY_ON_FALSE_RETURN_VAL(eina_init(), --_edje_init_count);
_edje_default_log_dom = eina_log_domain_register

View File

@ -170,8 +170,6 @@
* char tmp[128];
* int i;
*
* srand(time(NULL));
*
* for (i = 0; i < request; ++i)
* eina_convert_itoa(rand(), tmp);
* }
@ -182,8 +180,6 @@
* char tmp[128];
* int i;
*
* srand(time(NULL));
*
* for (i = 0; i < request; ++i)
* eina_convert_xtoa(rand(), tmp);
* }
@ -203,8 +199,6 @@
* int *data;
* int i;
*
* srand(time(NULL));
*
* array = eina_array_new(64);
*
* for (i = 0; i < request; ++i)
@ -228,8 +222,6 @@
* int *data;
* int i;
*
* srand(time(NULL));
*
* for (i = 0; i < request; ++i)
* {
* data = (int *)malloc(sizeof(int));

View File

@ -30,6 +30,14 @@
# include <unistd.h>
#endif
#ifndef _WIN32
# ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
# endif
# include <sys/stat.h>
# include <fcntl.h>
#endif
#ifdef HAVE_MCHECK_H
# ifdef HAVE_MTRACE
# define MT 1
@ -283,7 +291,20 @@ eina_init(void)
if (EINA_LIKELY(_eina_main_count > 0))
return ++_eina_main_count;
srand(time(NULL));
#ifdef _WIN32
#else
int fd = open("/dev/urandom", O_RDONLY);
if (fd >= 0)
{
unsigned int val;
if (read(fd, &val, sizeof(val)) == sizeof(val)) srand(val);
else srand(time(NULL));
close(fd);
}
else
#endif
srand(time(NULL));
while (eina_seed == 0)
eina_seed = rand();

View File

@ -4170,8 +4170,6 @@ _elm_map_efl_canvas_group_group_add(Eo *obj, Elm_Map_Data *priv)
// FIXME: Tile Provider is better to provide tile size!
priv->tsize = DEFAULT_TILE_SIZE;
srand(time(NULL));
priv->id = ((int)getpid() << 16) | id_num;
id_num++;
_grid_all_create(priv);

View File

@ -25,8 +25,6 @@ embryo_init(void)
if (++_embryo_init_count != 1)
return _embryo_init_count;
srand(time(NULL));
if (!eina_init())
return --_embryo_init_count;

View File

@ -812,7 +812,6 @@ EFL_START_TEST(efl_test_promise_future_race)
2.0, 1.0, 0.5, 0.1, 4.5, 2.3, 5.6, 1.0, 0.5, 0.3
};
srand(time(NULL));
fail_if(!ecore_init());
for (i = 0; i < len - 1; i++)
{

View File

@ -270,12 +270,8 @@ EFL_START_TEST(eina_test_hash_int32_fuzze)
Eina_Hash *hash;
unsigned int *r, *array;
unsigned int i;
unsigned int seed;
unsigned int num_loops = 10000;
seed = time(NULL);
srand(seed);
hash = eina_hash_int32_new(NULL);
array = malloc(sizeof(int) * num_loops);
@ -312,8 +308,6 @@ EFL_START_TEST(eina_test_hash_int64_fuzze)
uint64_t i;
uint64_t num_loops = 10000;
srand(time(NULL));
hash = eina_hash_int64_new(NULL);
array = malloc(sizeof(int64_t) * num_loops);
@ -347,13 +341,9 @@ EFL_START_TEST(eina_test_hash_string_fuzze)
{
Eina_Hash *hash;
unsigned int i;
unsigned int seed;
char *array;
unsigned int num_loops = 100;
seed = time(NULL);
srand(seed);
hash = eina_hash_string_superfast_new(NULL);
array = malloc(num_loops * 10);

View File

@ -173,8 +173,6 @@ EINA_TEST_START(eina_stringshare_collision)
char buffer[50];
int i;
srand(time(NULL));
ea = eina_array_new(256);
fail_if(!ea);