-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrand.cpp
More file actions
122 lines (116 loc) · 2.86 KB
/
rand.cpp
File metadata and controls
122 lines (116 loc) · 2.86 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//#include"sensor2D.h"
//#include"sensor.h"
//#include<chrono>
//#include<ctime>
//#include<stdlib.h>
//#include<iostream>
//#include <algorithm>
//using namespace std;
//
//
//void gettimeofday(struct timeval* tv)
//{
// auto time_now = std::chrono::system_clock::now();
// std::chrono::system_clock::time_point tp = std::chrono::system_clock::now();
// auto duration_in_s =
// std::chrono::duration_cast<std::chrono::seconds>(time_now.time_since_epoch()).count();
// auto duration_in_us =
// std::chrono::duration_cast<std::chrono::microseconds>(time_now.time_since_epoch()).count();
//
// tv->tv_sec = duration_in_s;
// tv->tv_usec = duration_in_us;
//}
//
//double myrandom(double min, double max) {
// return rand() / (1.0 * RAND_MAX) * (max - min) + min;
//}
//
//bool randam(sensor2D* point, int NUM)
//{
// int i, n = NUM;
// long seed;
// double delta;
// double* rnda = new double[NUM];
// struct timeval time;
// gettimeofday(&time);
//
// seed = (time.tv_sec * 1000) + (time.tv_usec / 1000);
// seed = 1564584525524;
// srand(seed);
// cout << "Seed=\t" << seed << endl;
//
// for (i = 0; i < n; i++) {
// rnda[i] = myrandom(0, DIS - DRANGE);
// }
// sort(rnda, rnda + n);
// // position
// for (i = 0; i < n; i++) {
// point[i].position = rnda[i];
// }
//
// gettimeofday(&time);
// seed = (time.tv_sec * 1000) + (time.tv_usec / 1000);
// srand(seed);
// //c
// for (i = 0; i < n; i++) {
// point[i].c = myrandom(1, HEIGHT_BOUNDARY);
// point[i].b = point[i].c * myrandom(SHAPE_COEF_LOW, SHAPE_COEF_HIGH);
// }
//
// //Êý¾ÝÁ¿
// for (i = 0; i < n; i++) {
// point[i].dataAmount = myrandom(1, HEIGHT_BOUNDARY / 2);
// }
//
//
// i = 1;
// delta = point[i].position;
// for (i = 1; i < n; i++) {
// point[i].position -= delta;
// }
//
// return true;
//}
/*
bool randam(sensor* point, int NUM)
{
int i, n = NUM;
long seed;
double delta;
double* rnda = new double[NUM];
struct timeval time;
gettimeofday(&time);
seed = (time.tv_sec * 1000) + (time.tv_usec / 1000);
seed = 1564584525524;
srand(seed);
cout << "Seed=\t" << seed << endl;
for (i = 0; i < n; i++) {
rnda[i] = myrandom(0, DIS - DRANGE);
}
sort(rnda, rnda + n);
for (i = 0; i < n; i++) {
point[i].start = rnda[i];
}
for (i = 0; i < n; i++) {
rnda[i] = point[i].start + myrandom(1, DRANGE * 2 - 1);
}
sort(rnda, rnda + n);
for (i = 0; i < n; i++) {
if ((rnda[i] - point[i].start) / 2 > VISION)
point[i].finish = point[i].start + 2 * VISION - 1e-1;
else
point[i].finish = rnda[i];
point[i].position = (point[i].finish - point[i].start) / 2 + point[i].start;
point[i].time = max((point[i].finish - point[i].start) / 30, myrandom(0, TAU * 2));
// point[i].position=rnda[i];
// point[i].finish=2*point[i].position-point[i].start;
// point[i].time=myrandom(0, TAU*2);
}
i = 0;
delta = point[i].start;
point[i].start -= delta;
point[i].position -= delta;
point[i].finish -= delta;
return true;
}
*/