-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandomLines.java
38 lines (34 loc) · 962 Bytes
/
RandomLines.java
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
import java.util.Random;
/**
* @author Anuj
*
*/
public class RandomLines {
private Random r;
private int numberOfLines = 0;
private final int upperBound = 99900;
//private final int upperBound = 100000;
/**
*
*/
public RandomLines(int numberOfLines) {
r = new Random();
this.numberOfLines = numberOfLines;
}
public Line[] lines() {
Line[] lineSegments = new Line[numberOfLines*2];
for (int i = 0; i < 2*numberOfLines; i+= 2) {
int randomIntX = r.nextInt(upperBound);
int randomIntY = r.nextInt(upperBound);
Line horizontalLine = new Line(new Point(randomIntX, randomIntY),
new Point(randomIntX + 100, randomIntY));
lineSegments[i] = horizontalLine;
randomIntX = r.nextInt(upperBound);
randomIntY = r.nextInt(upperBound);
Line verticalLine = new Line(new Point(randomIntX, randomIntY),
new Point(randomIntX, randomIntY + 100), true);
lineSegments[i+1] = verticalLine;
}
return lineSegments;
}
}