/*M*
//
//               INTEL CORPORATION PROPRIETARY INFORMATION
//  This software is supplied under the terms of a license agreement or
//  nondisclosure agreement with Intel Corporation and may not be copied
//  or disclosed except in accordance with the terms of that agreement.
//        Copyright (c) 1995 Intel Corporation. All Rights Reserved.
//
//  RCS:
//      $Source: d:/rcs/nsp20/include/nsprand.h $
//      $Revision: 1.4 $
//      $Date: 1995/08/07 11:01:32 $
//
//  Purpose: NSP
*M*/

#if !defined _NSPRAND_H || defined _NSP_BLDPCS
# define _NSPRAND_H

/*
   Uniform distribution.
   Algorithm by G.Marsaglia and A.Zaman (Computers in Physics, vol.8,
   #1, 1994, 117) are used to build generator of uniformly distributed
   random numbers.
*/
#ifndef _NSP_BLDPCS

typedef struct NSPSRandUniState {
   unsigned int seed1[3], seed2, carry; /* Variables of the algorithm       */
   float low,muler;                    /* Lower value and scale multiplier */
} NSPSRandUniState;

typedef struct NSPDRandUniState {
   unsigned int seed1[3], seed2, carry, junk;
   double low,muler;
} NSPDRandUniState;

typedef struct NSPSRandUniState NSPCRandUniState;
typedef struct NSPSRandUniState NSPWRandUniState;
typedef struct NSPDRandUniState NSPZRandUniState;

#endif

NSPAPI(void,nspsRandUniInit,(float seed, float  low, float  high,
                             NSPSRandUniState  *statePtr));
NSPAPI(void,nspcRandUniInit,(float seed, float  low, float  high,
                             NSPCRandUniState  *statePtr));
NSPAPI(void,nspdRandUniInit,(double seed,double low, double high,
                             NSPDRandUniState  *statePtr));
NSPAPI(void,nspzRandUniInit,(double seed,double low, double high,
                             NSPZRandUniState  *statePtr));
NSPAPI(void,nspwRandUniInit,(short seed,short low,short high,
                             NSPWRandUniState  *statePtr));

NSPAPI(float, nspsRandUni,(NSPSRandUniState *statePtr));
NSPAPI(SCplx, nspcRandUni,(NSPCRandUniState *statePtr));
NSPAPI(double,nspdRandUni,(NSPDRandUniState *statePtr));
NSPAPI(DCplx, nspzRandUni,(NSPZRandUniState *statePtr));
NSPAPI(short, nspwRandUni,(NSPWRandUniState *statePtr));

NSPAPI(void,nspsbRandUni,(NSPSRandUniState  *statePtr,
                          float *samps,  int sampsLen));
NSPAPI(void,nspcbRandUni,(NSPCRandUniState  *statePtr,
                          SCplx *samps,  int sampsLen));
NSPAPI(void,nspdbRandUni,(NSPDRandUniState  *statePtr,
                          double *samps, int sampsLen));
NSPAPI(void,nspzbRandUni,(NSPZRandUniState  *statePtr,
                          DCplx *samps,  int sampsLen));
NSPAPI(void,nspwbRandUni,(NSPWRandUniState  *statePtr,
                          short *samps,  int sampsLen));

/*
   Normal distribution.
   Algorithm by G.Box and M.Muller and by G.Marsaglia (Reference:
   D.Knuth. The Art of Computer Programming. vol.2, 1969) are used
   to build generator of normally distributed random numbers.
*/

#ifndef _NSP_BLDPCS

typedef struct NSPSRandGausState {
   unsigned int seed1[3],seed2,carry;  /* Variables of the algorithm         */
   float mean,stDev;                   /* Mean and standard deviation values */
   int useExtra;                       /* Flag to use extra value            */
   float extraValue;                   /* Value computed early               */
} NSPSRandGausState;
                       
typedef struct NSPDRandGausState {
   unsigned int seed1[3],seed2,carry;
   double mean,stDev;
   int useExtra;
   double extraValue;
} NSPDRandGausState;

typedef struct NSPWRandGausState {
   unsigned int seed1[3],seed2,carry;
   short mean,stDev;
   int useExtra;
   short extraValue;
} NSPWRandGausState;

typedef struct NSPSRandGausState NSPCRandGausState;
typedef struct NSPDRandGausState NSPZRandGausState;

#endif

NSPAPI(void,nspsRandGausInit,(float seed,float mean,float stDev,
                              NSPSRandGausState *statePtr));
NSPAPI(void,nspcRandGausInit,(float seed,float mean,float stDev,
                              NSPCRandGausState *statePtr));
NSPAPI(void,nspdRandGausInit,(double seed,double mean,double stDev,
                              NSPDRandGausState *statePtr));
NSPAPI(void,nspzRandGausInit,(double seed,double mean,double stDev,
                              NSPZRandGausState *statePtr));
NSPAPI(void,nspwRandGausInit,(short seed,short mean,short stDev,
                              NSPWRandGausState *statePtr));

NSPAPI(float, nspsRandGaus,(NSPSRandGausState *statePtr));
NSPAPI(SCplx, nspcRandGaus,(NSPCRandGausState *statePtr));
NSPAPI(double,nspdRandGaus,(NSPDRandGausState *statePtr));
NSPAPI(DCplx, nspzRandGaus,(NSPZRandGausState *statePtr));
NSPAPI(short, nspwRandGaus,(NSPWRandGausState *statePtr));

NSPAPI(void,nspsbRandGaus,(NSPSRandGausState *statePtr,
                           float *samps,  int sampsLen));
NSPAPI(void,nspcbRandGaus,(NSPCRandGausState *statePtr,
                           SCplx *samps,  int sampsLen));
NSPAPI(void,nspdbRandGaus,(NSPDRandGausState *statePtr,
                           double *samps, int sampsLen));
NSPAPI(void,nspzbRandGaus,(NSPZRandGausState *statePtr,
                           DCplx *samps,  int sampsLen));
NSPAPI(void,nspwbRandGaus,(NSPWRandGausState *statePtr,
                           short *samps,  int sampsLen));

#endif
