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:
parent
849922881d
commit
8201a52cec
|
@ -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),
|
// We don't need high quality random numbers (which might not be available),
|
||||||
// just non-repeating numbers!
|
// 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++)
|
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)
|
TraversalClient::TraversalClient(ENetHost* netHost, const std::string& server, const u16 port)
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <random>
|
||||||
#include <enet/enet.h>
|
#include <enet/enet.h>
|
||||||
#include "Common/Common.h"
|
#include "Common/Common.h"
|
||||||
#include "Common/Thread.h"
|
#include "Common/Thread.h"
|
||||||
|
|
Loading…
Reference in New Issue