-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.hpp
38 lines (29 loc) · 848 Bytes
/
util.hpp
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
30
31
32
33
34
35
36
37
38
#ifndef __UTIL_HPP__
#define __UTIL_HPP__
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include "main.hpp"
// Return a number uniformly between [0, 1]
double rand01();
// Return a random integer between [0, end)
unsigned int randRange(unsigned int end);
// Return a random number between [start, end)
int randRange(int start, int end);
// Extract a value from a string
template<typename T>
void strExtract(std::string &str, T &val) {
std::istringstream iss(str);
iss >> val;
}
template<typename T>
T strExtract(std::string &str) {
T val;
strExtract(str, val);
return val;
}
// encode/decode values to/from symbol lists
unsigned int decode(const symbol_list_t &symlist, unsigned int bits);
void encode(symbol_list_t &symlist, unsigned int value, unsigned int bits);
#endif // __UTIL_HPP__