Merge pull request #613 from jg1uaa/master
replace rand() -> MT19937 random number generator
This commit is contained in:
commit
ee2e997cfd
4 changed files with 22 additions and 11 deletions
|
@ -66,7 +66,8 @@ m_height(0),
|
||||||
m_location(),
|
m_location(),
|
||||||
m_description(),
|
m_description(),
|
||||||
m_url(),
|
m_url(),
|
||||||
m_beacon(false)
|
m_beacon(false),
|
||||||
|
m_random()
|
||||||
{
|
{
|
||||||
assert(!address.empty());
|
assert(!address.empty());
|
||||||
assert(port > 0U);
|
assert(port > 0U);
|
||||||
|
@ -85,11 +86,13 @@ m_beacon(false)
|
||||||
m_id[2U] = id >> 8;
|
m_id[2U] = id >> 8;
|
||||||
m_id[3U] = id >> 0;
|
m_id[3U] = id >> 0;
|
||||||
|
|
||||||
CStopWatch stopWatch;
|
std::random_device rd;
|
||||||
::srand(stopWatch.start());
|
std::mt19937 mt(rd());
|
||||||
|
m_random = mt;
|
||||||
|
|
||||||
m_streamId[0U] = ::rand() + 1U;
|
std::uniform_int_distribution<uint32_t> dist(0x00000001, 0xfffffffe);
|
||||||
m_streamId[1U] = ::rand() + 1U;
|
m_streamId[0U] = dist(m_random);
|
||||||
|
m_streamId[1U] = dist(m_random);
|
||||||
}
|
}
|
||||||
|
|
||||||
CDMRNetwork::~CDMRNetwork()
|
CDMRNetwork::~CDMRNetwork()
|
||||||
|
@ -246,6 +249,7 @@ bool CDMRNetwork::write(const CDMRData& data)
|
||||||
|
|
||||||
unsigned int slotIndex = slotNo - 1U;
|
unsigned int slotIndex = slotNo - 1U;
|
||||||
|
|
||||||
|
std::uniform_int_distribution<uint32_t> dist(0x00000001, 0xfffffffe);
|
||||||
unsigned char dataType = data.getDataType();
|
unsigned char dataType = data.getDataType();
|
||||||
if (dataType == DT_VOICE_SYNC) {
|
if (dataType == DT_VOICE_SYNC) {
|
||||||
buffer[15U] |= 0x10U;
|
buffer[15U] |= 0x10U;
|
||||||
|
@ -253,10 +257,10 @@ bool CDMRNetwork::write(const CDMRData& data)
|
||||||
buffer[15U] |= data.getN();
|
buffer[15U] |= data.getN();
|
||||||
} else {
|
} else {
|
||||||
if (dataType == DT_VOICE_LC_HEADER)
|
if (dataType == DT_VOICE_LC_HEADER)
|
||||||
m_streamId[slotIndex] = ::rand() + 1U;
|
m_streamId[slotIndex] = dist(m_random);
|
||||||
|
|
||||||
if (dataType == DT_CSBK || dataType == DT_DATA_HEADER)
|
if (dataType == DT_CSBK || dataType == DT_DATA_HEADER)
|
||||||
m_streamId[slotIndex] = ::rand() + 1U;
|
m_streamId[slotIndex] = dist(m_random);
|
||||||
|
|
||||||
buffer[15U] |= (0x20U | dataType);
|
buffer[15U] |= (0x20U | dataType);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <random>
|
||||||
|
|
||||||
class CDMRNetwork
|
class CDMRNetwork
|
||||||
{
|
{
|
||||||
|
@ -106,6 +107,7 @@ private:
|
||||||
std::string m_url;
|
std::string m_url;
|
||||||
|
|
||||||
bool m_beacon;
|
bool m_beacon;
|
||||||
|
std::mt19937 m_random;
|
||||||
|
|
||||||
bool writeLogin();
|
bool writeLogin();
|
||||||
bool writeAuthorisation();
|
bool writeAuthorisation();
|
||||||
|
|
|
@ -44,14 +44,16 @@ m_inId(0U),
|
||||||
m_buffer(1000U, "D-Star Network"),
|
m_buffer(1000U, "D-Star Network"),
|
||||||
m_pollTimer(1000U, 60U),
|
m_pollTimer(1000U, 60U),
|
||||||
m_linkStatus(LS_NONE),
|
m_linkStatus(LS_NONE),
|
||||||
m_linkReflector(NULL)
|
m_linkReflector(NULL),
|
||||||
|
m_random()
|
||||||
{
|
{
|
||||||
m_address = CUDPSocket::lookup(gatewayAddress);
|
m_address = CUDPSocket::lookup(gatewayAddress);
|
||||||
|
|
||||||
m_linkReflector = new unsigned char[DSTAR_LONG_CALLSIGN_LENGTH];
|
m_linkReflector = new unsigned char[DSTAR_LONG_CALLSIGN_LENGTH];
|
||||||
|
|
||||||
CStopWatch stopWatch;
|
std::random_device rd;
|
||||||
::srand(stopWatch.start());
|
std::mt19937 mt(rd());
|
||||||
|
m_random = mt;
|
||||||
}
|
}
|
||||||
|
|
||||||
CDStarNetwork::~CDStarNetwork()
|
CDStarNetwork::~CDStarNetwork()
|
||||||
|
@ -85,7 +87,8 @@ bool CDStarNetwork::writeHeader(const unsigned char* header, unsigned int length
|
||||||
buffer[4] = busy ? 0x22U : 0x20U;
|
buffer[4] = busy ? 0x22U : 0x20U;
|
||||||
|
|
||||||
// Create a random id for this transmission
|
// Create a random id for this transmission
|
||||||
m_outId = (::rand() % 65535U) + 1U;
|
std::uniform_int_distribution<uint16_t> dist(0x0001, 0xfffe);
|
||||||
|
m_outId = dist(m_random);
|
||||||
|
|
||||||
buffer[5] = m_outId / 256U; // Unique session id
|
buffer[5] = m_outId / 256U; // Unique session id
|
||||||
buffer[6] = m_outId % 256U;
|
buffer[6] = m_outId % 256U;
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <random>
|
||||||
|
|
||||||
class CDStarNetwork {
|
class CDStarNetwork {
|
||||||
public:
|
public:
|
||||||
|
@ -64,6 +65,7 @@ private:
|
||||||
CTimer m_pollTimer;
|
CTimer m_pollTimer;
|
||||||
LINK_STATUS m_linkStatus;
|
LINK_STATUS m_linkStatus;
|
||||||
unsigned char* m_linkReflector;
|
unsigned char* m_linkReflector;
|
||||||
|
std::mt19937 m_random;
|
||||||
|
|
||||||
bool writePoll(const char* text);
|
bool writePoll(const char* text);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue