Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION] Whether could refactor the calle of rand #12756

Open
Bannirui opened this issue Nov 13, 2023 · 0 comments
Open

[QUESTION] Whether could refactor the calle of rand #12756

Bannirui opened this issue Nov 13, 2023 · 0 comments

Comments

@Bannirui
Copy link
Contributor

Hi,

As the src code in https://github.com/redis/redis/blob/unstable/src/server.c#L6941-L6943.

I have little questions for help:

  • why should we depend on both of rand(...) and radom(...), shall we just select one of them
  • is it necessary to call time(...) cuz we have got the value of time in seconds via gettimeofday(...), maybe we could save the of cost of calling time(...)

to be short, the expect as below:

gettimeofday(&tv,NULL);
srandom(tv.tv_sec^getpid()^tv.tv_usec);

or

gettimeofday(&tv,NULL);
srandom((tv.tv_sec*1000000+tv.tv_usec)^getpid());

i don't konw if it is okay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant