public static void main(String[] args) { int n = 10; StdDraw.setCanvasSize(160, 640); StdDraw.setXscale(-1, n + 1); StdDraw.setPenRadius(0.006); double[] a = new double[n]; for (int i = 0; i < n; i++) a[i] = StdRandom.uniform(0.0, 1.0); sort(a); }
public static void drawRandConn(int N, double p) { StdDraw.setCanvasSize(512, 512); StdDraw.setScale(-1.0, 1.0); StdDraw.setPenRadius(.025); double[][] d = new double[N][2]; for (int i = 0; i < N; i++) { d[i][0] = Math.cos(2 * Math.PI * i / N); d[i][1] = Math.sin(2 * Math.PI * i / N); StdDraw.point(d[i][0], d[i][1]); } StdDraw.setPenRadius(); StdDraw.setPenColor(StdDraw.GRAY); for (int i = 0; i < N - 1; i++) for (int j = i + 1; j < N; j++) if (StdRandom.bernoulli(p)) StdDraw.line(d[i][0], d[i][1], d[j][0], d[j][1]); }