Traversal: Use a decent PRNG instead of rand()

we don’t need cryptosecure random, but having a uniform distribution is
always better.
This commit is contained in:
mathieui 2015-03-10 01:47:29 +01:00
parent 849922881d
commit 8201a52cec
2 changed files with 4 additions and 2 deletions

View File

@ -7,9 +7,10 @@ static void GetRandomishBytes(u8* buf, size_t size)
{
// We don't need high quality random numbers (which might not be available),
// just non-repeating numbers!
srand(enet_time_get());
static std::mt19937 prng(enet_time_get());
static std::uniform_int_distribution<unsigned int> u8_distribution(0, 255);
for (size_t i = 0; i < size; i++)
buf[i] = rand() & 0xff;
buf[i] = u8_distribution(prng);
}
TraversalClient::TraversalClient(ENetHost* netHost, const std::string& server, const u16 port)

View File

@ -4,6 +4,7 @@
#include <functional>
#include <list>
#include <memory>
#include <random>
#include <enet/enet.h>
#include "Common/Common.h"
#include "Common/Thread.h"