drogonframework / drogon

Drogon: A C++14/17/20 based HTTP web application framework running on Linux/macOS/Unix/Windows
MIT License
11.63k stars 1.12k forks source link

Replace rejection sampling and remove use of rand() #2180

Closed marty1885 closed 1 month ago

marty1885 commented 1 month ago

The old code uses rejection sampling. Trying to get number between 0~61 from 0~RAND_MAX (on Windows this is 15bits and on Linux 32bits) is extremely slow. This patch fixes that by using C++'s distribution class.

Also replaces rand() with C++ random engines since OpenBSD is complaining about it.

ld: warning: Utilities.cc(Utilities.cc.o:(drogon::utils::genRandomString(int)) in archive ../libdrogon.a): warning: rand() may return deterministic values, is that what you want?
marty1885 commented 1 month ago

@an-tao How can we fix the cpplint problem?

an-tao commented 1 month ago

@an-tao How can we fix the cpplint problem?

Temporarily solved