-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAddress_Generator
90 lines (72 loc) · 1.69 KB
/
Address_Generator
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Address_Generator.cpp : This file contains the 'main' function. Program execution begins and ends ther
#include<cstdlib>
#include<string>
#include<iostream>
#include <fstream>
#include <sstream>
#include <time.h>
using namespace std;
//function to generate r or w
char generate_read_write()
{
int randomNumber;
randomNumber = (rand() % 10);
//cout << randomNumber<<endl;
if (randomNumber % 2 == 0)
return 'w';
else
return'r';
}
//function to generate random number between 1-1000 for address 2
int generate_address2()
{
return ((rand() % 1000));
}
unsigned int generate_address1() {
unsigned int max_address = 4294967295;
int choose_random = rand() % 4;
if (choose_random == 1)
return(rand() % max_address);
else if(choose_random == 2)
return(rand() % (max_address)+4190208);
else if (choose_random == 3)
return(rand() % (max_address)+49496729);
else
return(rand() % (max_address)+4095);
}
int main()
{
ofstream outputfile;
outputfile.open("input.txt");
char letter;
unsigned seed;
int addr1;
int addr2;
int randomNumber;
seed = time(0);
srand(seed);
randomNumber = (rand() % 10) + 1;
outputfile << "p " << randomNumber;
letter = generate_read_write();
int num_lines = (rand() % 40) + 10; //number of lines for generating addresses
for (int i = 0; i < num_lines; ++i)
{
outputfile << endl;
for (int i = 0; i < 5; ++i)
{
letter = generate_read_write();
if (letter == 'r')
{
addr1 = generate_address1();
outputfile << "r " << addr1 << " ";
}
else //write operation
{
addr1 = generate_address1();
addr2 = generate_address2();
outputfile << "w " << addr1 << " " << addr2 << " ";
}
}
}
outputfile.close();
}