Here you can find the source of randomPointsFromUnitSphere(int n)
public static double[][] randomPointsFromUnitSphere(int n)
//package com.java2s; //License from project: Open Source License public class Main { public static double[][] randomPointsFromUnitSphere(int n) { if (n <= 0) { throw new IllegalArgumentException(); }/*from ww w .j av a 2 s. c o m*/ double[][] result = new double[n][3]; for (int i = 0; i < n; i++) { //Spherical Coordinates! double phi = Math.PI * Math.random(); double theta = 2 * Math.PI * Math.random(); double x = Math.cos(theta) * Math.sin(phi); double y = Math.sin(theta) * Math.sin(phi); double z = Math.cos(phi); result[i][0] = x; result[i][1] = y; result[i][2] = z; } return result; } }