Numworks Epsilon  1.4.1
Graphing Calculator Operating System
event_generator.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <random>
4 #include <cstdio>
5 #include <ion/events.h>
6 
7 void writeEventsToFile(std::ofstream & file, int numberOfEvents, std::mt19937 & rng) {
8  std::uniform_int_distribution<int> distribution(0,4*Ion::Events::Event::PageSize);
9 
10  int i = numberOfEvents;
11  while (i > 0) {
12  int prEventId = distribution(rng);
13  Ion::Events::Event e(prEventId);
14  if (e.isDefined() && e != Ion::Events::Termination) {
15  i--;
16  file << (unsigned char)(prEventId);
17  }
18  }
19 }
20 
21 int main(int argc, char * argv[]) {
22  if (argc != 3) {
23  std::cerr << "Usage: event_generator <count> <length_avg>" << std::endl;
24  return -1;
25  }
26 
27  std::random_device r;
28  std::mt19937 mt(r());
29 
30  int count = std::stoi(argv[1]);
31  int lengthAvg = std::stoi(argv[2]);
32  int lengthStdDev = lengthAvg;
33 
34  std::normal_distribution<> lengthDistribution(lengthAvg, lengthStdDev);
35 
36  for (int i=0; i<count; i++) {
37  char buffer[32];
38  sprintf(buffer, "scenario_%04d.bin", i);
39  std::string fileName(buffer);
40  std::ofstream file;
41  file.open(fileName);
42  writeEventsToFile(file, lengthDistribution(mt), mt);
43  file.close();
44  }
45 
46  return 0;
47 }
bool isDefined() const
Definition: events.cpp:126
void writeEventsToFile(std::ofstream &file, int numberOfEvents, std::mt19937 &rng)
int main(int argc, char *argv[])
static constexpr int PageSize
Definition: events.h:36
constexpr Event Termination
Definition: events.h:216