Skip to content

Instantly share code, notes, and snippets.

@Khalefa
Created September 25, 2018 00:46
Show Gist options
  • Save Khalefa/b1a705a41cd3f9b572c8377bd05a22b6 to your computer and use it in GitHub Desktop.
Save Khalefa/b1a705a41cd3f9b572c8377bd05a22b6 to your computer and use it in GitHub Desktop.
records
template <int size>
struct record_int {
int x;
char P[size - sizeof(x)];
};
template <int size>
struct record_float {
float x;
char P[size - sizeof(x)];
};
template <int size>
struct record_string {
string x;
char P[size - sizeof(x)];
};
template <int size>
void generate_record_int(record_int<size> * arr, int n) {
std::random_device rd; //Will be used to obtain a seed for the random number engine
std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd()
std::uniform_int_distribution<> dis(0, 26 - 1);
arr = new record_int<size>[n];
for (int i = 0; i < n; ++i) {
arr[i] = dis(gen);
}
}
int main() {
record_int<16> *arr;
generate_record_int<16>(arr, 100);
record_int<1024> *arrb;
generate_record_int<1024>(arrb, 100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment