package nxm.sys.libm;

import nxm.sys.inc.Constants;

/**
   Performs the RandomPseudo operation on arrays. <br>
   Pseudo-random number generator (PRNG) using java.util.Random via Math.random(). <br>
   See {@link Operator} for a description of the available I/O Modes.
   @author  Auto-Generated
   @see     Operator
*/
@SuppressWarnings("cast")
public final class RandomPseudo extends Operator implements Constants {

  /** Create a new instance. */
  public RandomPseudo() {
    super();
  }

  /** Create a new instance.
      @param flags The processing flags to use.
   */
  public RandomPseudo (int flags) {
    super(flags);
  }

  /** Create a new instance.
      @param scale The scale factor to use.
   */
  public RandomPseudo (double scale) {
    super(scale);
  }

  /** Create a new instance.
      @param flags The processing flags to use.
      @param scale The scale factor to use.
   */
  public RandomPseudo (int flags, double scale) {
    super(flags,scale);
  }

  public final int validate (char type, int n, int mode) {
    switch (mode) {
      case S: return n;
      case C: return n;
      case V: return n;
      default: return NOSUPPORT;
    }
  }

  public final int process (double[][] v, int n, int mode) {
    switch (mode) {
      case S: S(v[0],n); return n;
      case C: C(v[0],n); return n;
      case V: V(v[0],n); return n;
      default:  return NOSUPPORT;
    }
  }

  public final int process (double[][] v, int n, int mode, double scale) {
    switch (mode) {
      case S: S(v[0],n); return n;
      case C: C(v[0],n); return n;
      case V: V(v[0],n); return n;
      default:  return NOSUPPORT;
    }
  }

  /** Apply this operator to mode {@link Operator#S} data.
      @param a     The first  operand.
      @param n     The number of elements to operate on.
      @see #process(double[][],int,int)
   */
  public static final void S (double[] a, int n) {
      for (int i=0; i<n; i++) {
        a[i]=(double)Math.random();
      }
  }

  /** Apply this operator to mode {@link Operator#C} data.
      @param a     The first  operand.
      @param n     The number of elements to operate on.
      @see #process(double[][],int,int)
   */
  public static final void C (double[] a, int n) {
      for (int i=0,j=0; i<n; i++,j+=2) {
        a[j]=(double)Math.random();
        a[j+1]=(double)Math.random();
      }
  }

  /** Apply this operator to mode {@link Operator#V} data.
      @param a     The first  operand.
      @param n     The number of elements to operate on.
      @see #process(double[][],int,int)
   */
  public static final void V (double[] a, int n) {
      for (int i=0,k=0; i<n; i++,k+=3) {
        a[k]=(double)Math.random();
        a[k+1]=(double)Math.random();
        a[k+2]=(double)Math.random();
      }
  }

  public final int process (float[][] v, int n, int mode) {
    switch (mode) {
      case S: S(v[0],n); return n;
      case C: C(v[0],n); return n;
      case V: V(v[0],n); return n;
      default:  return NOSUPPORT;
    }
  }

  public final int process (float[][] v, int n, int mode, double scale) {
    switch (mode) {
      case S: S(v[0],n); return n;
      case C: C(v[0],n); return n;
      case V: V(v[0],n); return n;
      default:  return NOSUPPORT;
    }
  }

  /** Apply this operator to mode {@link Operator#S} data.
      @param a     The first  operand.
      @param n     The number of elements to operate on.
      @see #process(float[][],int,int)
   */
  public static final void S (float[] a, int n) {
      for (int i=0; i<n; i++) {
        a[i]=(float)Math.random();
      }
  }

  /** Apply this operator to mode {@link Operator#C} data.
      @param a     The first  operand.
      @param n     The number of elements to operate on.
      @see #process(float[][],int,int)
   */
  public static final void C (float[] a, int n) {
      for (int i=0,j=0; i<n; i++,j+=2) {
        a[j]=(float)Math.random();
        a[j+1]=(float)Math.random();
      }
  }

  /** Apply this operator to mode {@link Operator#V} data.
      @param a     The first  operand.
      @param n     The number of elements to operate on.
      @see #process(float[][],int,int)
   */
  public static final void V (float[] a, int n) {
      for (int i=0,k=0; i<n; i++,k+=3) {
        a[k]=(float)Math.random();
        a[k+1]=(float)Math.random();
        a[k+2]=(float)Math.random();
      }
  }

  public final int process (int[][] v, int n, int mode) {
    switch (mode) {
      case S: S(v[0],n); return n;
      case C: C(v[0],n); return n;
      case V: V(v[0],n); return n;
      default:  return NOSUPPORT;
    }
  }

  public final int process (int[][] v, int n, int mode, double scale) {
    switch (mode) {
      case S: S(v[0],n); return n;
      case C: C(v[0],n); return n;
      case V: V(v[0],n); return n;
      default:  return NOSUPPORT;
    }
  }

  /** Apply this operator to mode {@link Operator#S} data.
      @param a     The first  operand.
      @param n     The number of elements to operate on.
      @see #process(int[][],int,int)
   */
  public static final void S (int[] a, int n) {
      for (int i=0; i<n; i++) {
        a[i]=(int)Math.random();
      }
  }

  /** Apply this operator to mode {@link Operator#C} data.
      @param a     The first  operand.
      @param n     The number of elements to operate on.
      @see #process(int[][],int,int)
   */
  public static final void C (int[] a, int n) {
      for (int i=0,j=0; i<n; i++,j+=2) {
        a[j]=(int)Math.random();
        a[j+1]=(int)Math.random();
      }
  }

  /** Apply this operator to mode {@link Operator#V} data.
      @param a     The first  operand.
      @param n     The number of elements to operate on.
      @see #process(int[][],int,int)
   */
  public static final void V (int[] a, int n) {
      for (int i=0,k=0; i<n; i++,k+=3) {
        a[k]=(int)Math.random();
        a[k+1]=(int)Math.random();
        a[k+2]=(int)Math.random();
      }
  }

  public int getInputs() { return 0; }
  public int getOutputs() { return 1; }
}
