///////////////////////////////////////////////////////////////////////////
//                                                                       //
// Program file name: RMatrix.java                                       //
//                                                                       //
// © Tao Pang 2006                                                       //
//                                                                       //
// Last modified: January 18, 2006                                       //
//                                                                       //
// (1) This Java program is part of the book, "An Introduction to        //
//     Computational Physics, 2nd Edition," written by Tao Pang and      //
//     published by Cambridge University Press on January 19, 2006.      //
//                                                                       //
// (2) No warranties, express or implied, are made for this program.     //
//                                                                       //
///////////////////////////////////////////////////////////////////////////

// An example of using the random matrix.

import java.lang.*;
import java.util.Random;
public class RMatrix {
  public static void main(String argv[]) {
    int n = 5;
    double sigma = 1;
    double a[][] = rm(n, sigma);
    for (int i=0; i<n; ++i) {
      for (int j=0; j<n; ++j) {
        System.out.println("a[i][j] is " + a[i][j]);
      }
    }
  }

// Method to generate a random matrix for the Gaussian
// orthogonal ensemble with sigma being the standard
// deviation of the off-diagonal ellements.

  public static double[][] rm(int n, double sigma) {
    double a[][] = new double[n][n];
    double sigmad = Math.sqrt(2)*sigma;
    Random r = new Random();

    for (int i=0; i<n; ++i) 
      a[i][i] = sigmad*r.nextGaussian(); 

    for (int i=0; i<n; ++i) { 
      for (int j=0; j<i; ++j) {
        a[i][j] = sigma*r.nextGaussian(); 
        a[j][i] = a[i][j];
      }
    }
    return a;
  }
}
