Random.cc


#include "veclib.h"
#include "Random.h"

Random::Random() {
  seed = 0L;
}

Random::Random(long long s) {
  seed = s;
}

void Random::setSeed(long long s) {
  seed = s;
}

double Random::next() {
  return dran(&seed);
}

double* Random::randomArray(int n) {
  double* vec = new double[n];
  int one = 1;       // need a pointer to 1
  dranv(&seed, &n, vec, &one);
  return vec;
}

Vector &Random::randomVector(int n) {
  // creates vector with random entries
  double* vec = randomArray(n);
  return *new Vector(vec, n);
}

Matrix &Random::randomMatrix(int m, int n) {
  // creates matrix with random entries
  double* vec = randomArray(n*m);
  return *new Matrix(vec, m, n);
}

previous    contents     next

Peter Junglas 20.6.2000