-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtb.java
More file actions
60 lines (50 loc) · 1.76 KB
/
tb.java
File metadata and controls
60 lines (50 loc) · 1.76 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
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Random;
/**
* @author Iman Hosseini <hosseini.iman@yahoo.com>
* @version 1.0 (current version number of program)
* This program generates a C code with $N functions, then each two function call each other with probability $p
* The output is the code in a file called rg($N).c and a file for validation rg($N).vld
*/
public class tb{
static int N = 20;
static double p =0.6;
public static void main(String[] args){
Random r= new Random();
HashMap<Integer,HashSet<Integer>> edges = new HashMap<>();
if(args.length==1) N = Integer.parseInt(args[0]);
StringBuilder prog = new StringBuilder("// Generated by: tb \n\n");
StringBuilder vld = new StringBuilder();
vld.append(N+"\n");
for(int i=0;i<N;i++){
prog.append("void f"+(i)+"();\n");
}
prog.append("int main(){ return 0;}\n");
// System.out.println("hello world");
for(int i=0; i<N; i++){
// System.out.println(i);
prog.append("void f"+(i)+"(){");
for(int j=0; j<N; j++){
if(r.nextDouble() > p) {
prog.append("f"+(j)+"();");
vld.append(j+",");
}
}
vld.append(";");
prog.append("}\n");
}
String filename = "rg"+N+".c";
try (PrintWriter out = new PrintWriter(filename)) {
out.println(prog);
}catch(Exception e){
}
String vname= "rg"+N+".vld";
try (PrintWriter out = new PrintWriter(vname)) {
out.println(vld);
}catch(Exception e){
}
}
}