diff --git a/interactions.c b/interactions.c index 364447a..efb5d34 100644 --- a/interactions.c +++ b/interactions.c @@ -35,6 +35,8 @@ extern unsigned int status; extern char *start_path; extern char *input; +extern time_t seed; + char search_buffer[255]; unsigned int timeout_time = 0; unsigned int input_pass; @@ -595,6 +597,8 @@ void jump_to_dir(int passes, int index){ void order_by(int passes, int index){ (void)passes; + seed = time(NULL); + srand(seed); order_func = key_binding[index].black_magic; status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY); } diff --git a/main.c b/main.c index 3bb6da7..65e4474 100644 --- a/main.c +++ b/main.c @@ -102,6 +102,7 @@ int main(){ if (dt - t >= SETTINGS_RELOAD_DIR_DELTA) { time(&t); status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY); + srand(seed); } #endif @@ -205,7 +206,6 @@ void init() { char *start_path = getcwd(NULL, 0); setenv("START_PATH", start_path, 0); free(start_path); - time(&seed); - srand(seed); + seed = time(NULL); } diff --git a/sorting.c b/sorting.c index e7aae3e..93dacc8 100644 --- a/sorting.c +++ b/sorting.c @@ -103,21 +103,15 @@ int sort_alpha(const void *file0, const void *file1){ char *file_name1 = ((file*)file1)->file_name; return strcmp(file_name0, file_name1); } -int sort_random(const void *file0_, const void *file1_){ - file *file0 = (file*)file0_; - file *file1 = (file*)file1_; - if (file0->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR) && !(file1->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR))) { +int sort_random(const void *file0, const void *file1){ + + if (((file*)file0)->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR) && !(((file*)file1)->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR))) { return -1; } - if (!(file0->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR)) && file1->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR)) { + if (!(((file*)file0)->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR)) && ((file*)file1)->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR)) { return 1; } - int random = rand(); - if (random & 1) { - return 1; - } else { - return -1; - } + return ((rand()%3)-1); } int sort_type(const void *file0, const void *file1){