-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutils.h
More file actions
29 lines (25 loc) · 790 Bytes
/
utils.h
File metadata and controls
29 lines (25 loc) · 790 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#pragma once
#include <random>
static void byteToHex(const uint8_t* byte, char* hex, const int sizeInByte)
{
for (int i = 0; i < sizeInByte; i++){
sprintf(hex+i*2, "%02x", byte[i]);
}
}
static void hexToByte(const char* hex, uint8_t* byte, const int sizeInByte)
{
for (int i = 0; i < sizeInByte; i++){
sscanf(hex+i*2, "%2hhx", &byte[i]);
}
}
static void rand32(uint32_t* r) {
std::random_device rd;
static thread_local std::mt19937 generator(rd());
std::uniform_int_distribution<uint32_t> distribution(0,UINT32_MAX);
*r = distribution(generator);
}
static void rand64(uint64_t* r) {
static thread_local std::mt19937 generator;
std::uniform_int_distribution<uint64_t> distribution(0,UINT32_MAX);
*r = distribution(generator);
}