mirror of
https://gittea.dev/nova/th.git
synced 2025-10-22 02:40:15 -04:00
removal of rand() in sort_rand
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "file_previews.h"
|
#include "file_previews.h"
|
||||||
#include "backend.h"
|
#include "backend.h"
|
||||||
@@ -36,7 +37,7 @@ extern unsigned int status;
|
|||||||
extern char *start_path;
|
extern char *start_path;
|
||||||
extern char *input;
|
extern char *input;
|
||||||
|
|
||||||
extern time_t seed;
|
extern time_t *seed;
|
||||||
|
|
||||||
char search_buffer[255];
|
char search_buffer[255];
|
||||||
unsigned int timeout_time = 0;
|
unsigned int timeout_time = 0;
|
||||||
@@ -633,8 +634,10 @@ void jump_to_dir(int passes, int index){
|
|||||||
void order_by(int passes, int index){
|
void order_by(int passes, int index){
|
||||||
(void)passes;
|
(void)passes;
|
||||||
|
|
||||||
seed = time(NULL);
|
free(seed);
|
||||||
srand(seed);
|
seed = malloc(sizeof(time_t));
|
||||||
|
*seed = time(NULL);
|
||||||
|
|
||||||
order_func = key_binding[index].black_magic;
|
order_func = key_binding[index].black_magic;
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||||
}
|
}
|
||||||
|
8
main.c
8
main.c
@@ -21,7 +21,7 @@ unsigned int settings;
|
|||||||
unsigned int file_modifiers;
|
unsigned int file_modifiers;
|
||||||
unsigned int status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
unsigned int status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||||
char *start_path;
|
char *start_path;
|
||||||
time_t seed;
|
time_t *seed;
|
||||||
|
|
||||||
WINDOW *win_t;
|
WINDOW *win_t;
|
||||||
WINDOW *win_b;
|
WINDOW *win_b;
|
||||||
@@ -102,7 +102,6 @@ int main(){
|
|||||||
if (dt - t >= SETTINGS_RELOAD_DIR_DELTA) {
|
if (dt - t >= SETTINGS_RELOAD_DIR_DELTA) {
|
||||||
time(&t);
|
time(&t);
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||||
srand(seed);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -209,6 +208,9 @@ void init() {
|
|||||||
char *start_path = getcwd(NULL, 0);
|
char *start_path = getcwd(NULL, 0);
|
||||||
setenv("START_PATH", start_path, 0);
|
setenv("START_PATH", start_path, 0);
|
||||||
free(start_path);
|
free(start_path);
|
||||||
seed = time(NULL);
|
|
||||||
|
|
||||||
|
seed = malloc(sizeof(time_t));
|
||||||
|
*seed = time(NULL);
|
||||||
|
|
||||||
|
printf("%ld", (time_t)&seed);
|
||||||
}
|
}
|
||||||
|
20
sorting.c
20
sorting.c
@@ -4,12 +4,11 @@
|
|||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
|
|
||||||
extern time_t seed;
|
extern time_t *seed;
|
||||||
extern unsigned int settings;
|
|
||||||
extern unsigned int file_modifiers;
|
|
||||||
|
|
||||||
int skip_hidden_files(const struct dirent *entry){
|
int skip_hidden_files(const struct dirent *entry){
|
||||||
|
|
||||||
@@ -119,8 +118,21 @@ int sort_random(const void *file0, const void *file1){
|
|||||||
if (!(((file*)file0)->file_type & FILE_TYPE_DIR) && (((file*)file1)->file_type & FILE_TYPE_DIR)) {
|
if (!(((file*)file0)->file_type & FILE_TYPE_DIR) && (((file*)file1)->file_type & FILE_TYPE_DIR)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
time_t num = (time_t)&seed;
|
||||||
|
unsigned long i;
|
||||||
|
for (i = 0; i < 6; i++){
|
||||||
|
num ^= *seed;
|
||||||
|
if (num%2) {
|
||||||
|
num ^= (time_t)#
|
||||||
|
num ^= num << i;
|
||||||
|
} else {
|
||||||
|
num ^= (time_t)&seed;
|
||||||
|
num ^= num >> i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
num ^= getpid();
|
||||||
|
|
||||||
return ((rand()%3)-1);
|
return ((num%3) - 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
int sort_type(const void *file0, const void *file1){
|
int sort_type(const void *file0, const void *file1){
|
||||||
|
Reference in New Issue
Block a user