1
0
mirror of https://gittea.dev/nova/th.git synced 2025-10-21 10:20:15 -04:00

removal of rand() in sort_rand

This commit is contained in:
nova
2025-10-05 00:57:18 +02:00
parent e979209de3
commit f0ad6295f7
3 changed files with 27 additions and 10 deletions

View File

@@ -2,6 +2,7 @@
#include <pthread.h>
#include <dirent.h>
#include <string.h>
#include <unistd.h>
#include "file_previews.h"
#include "backend.h"
@@ -36,7 +37,7 @@ extern unsigned int status;
extern char *start_path;
extern char *input;
extern time_t seed;
extern time_t *seed;
char search_buffer[255];
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)passes;
seed = time(NULL);
srand(seed);
free(seed);
seed = malloc(sizeof(time_t));
*seed = time(NULL);
order_func = key_binding[index].black_magic;
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
}

8
main.c
View File

@@ -21,7 +21,7 @@ unsigned int settings;
unsigned int file_modifiers;
unsigned int status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
char *start_path;
time_t seed;
time_t *seed;
WINDOW *win_t;
WINDOW *win_b;
@@ -102,7 +102,6 @@ int main(){
if (dt - t >= SETTINGS_RELOAD_DIR_DELTA) {
time(&t);
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
srand(seed);
}
#endif
@@ -209,6 +208,9 @@ void init() {
char *start_path = getcwd(NULL, 0);
setenv("START_PATH", start_path, 0);
free(start_path);
seed = time(NULL);
seed = malloc(sizeof(time_t));
*seed = time(NULL);
printf("%ld", (time_t)&seed);
}

View File

@@ -4,12 +4,11 @@
#include <strings.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
#include "defines.h"
extern time_t seed;
extern unsigned int settings;
extern unsigned int file_modifiers;
extern time_t *seed;
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)) {
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 ^= 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){