Here you can find the source of randomPointsFromFigureEight(int n)
public static double[][] randomPointsFromFigureEight(int n)
//package com.java2s; //License from project: Open Source License public class Main { public static double[][] randomPointsFromFigureEight(int n) { if (n <= 0) { throw new IllegalArgumentException(); }/*from www. j a va 2s .c o m*/ double[][] result = new double[n][2]; for (int i = 0; i < n; i++) { /* * We first choose a point randomly on the unit circle */ double theta = 2 * Math.PI * Math.random(); double x = Math.cos(theta); double y = Math.sin(theta); /* * Now, we choose whether or not we're on the circle * x^2 + (y-1)^2 = 1 or x^2 + (y+1)^2 = 1 by shifting * the y coordinate either up 1 or down 1 randomly. */ y += Math.random() < 0.5 ? 1 : -1; result[i][0] = x; result[i][1] = y; } return result; } }