-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRandomGenerator.h
executable file
·52 lines (43 loc) · 1011 Bytes
/
RandomGenerator.h
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
@file RandomGenerator.h
@class RandomGenerator
@brief Clase que representa un Generador de Paquetes Aleatorio
@author Christopher Arredondo Flores
@date 28/9/2014
**/
#ifndef CLASS_RANDOMGENERATOR
#define CLASS_RANDOMGENERATOR
#include <string>
#include <fstream>
#include <stdlib.h>
#include <time.h>
using namespace std;
class RandomGenerator{
public:
static void generate(int MAX, int amount_pkgs){
/*
* @brief Método que Genera un archivo denominado loss con una cantidad MAX de paquetes perdidos
* @param MAX cantidad de paquetes a ser perdidos
* @param amount_pkgs Cantidad total de Paquetes
*/
ofstream file;
file.open("files/loss_random.loss",ofstream::out| ofstream::trunc);
srand(time(NULL));
//file << amount_pkgs<< "\n";
int x, count=0;
for (int i = 0; i < amount_pkgs; i++)
{
x = rand()%2;
if(x==0){
if(count<MAX){
count++;
}else{
x=1;
}
}
file << i << " " << x << "\n";
}
file.close();
}
};
#endif