#include <amsculib3/amsculib3.hpp>

namespace amscuda
{
namespace random
{

    __host__ void amscurand_tests1()
    {
        using namespace random;
        printf("Random number generator basic function test:\n");
        int I;
        // uint32_t q1;
        // float q2;
        // double q3;
        // int q4;
        
        rand_seed(0);
        printf("from seed 0...\n");
        for(I=0;I<10;I++)
        {
            printf("randui32[%d] = %u\n",I,randui32());
        }

        rand_seed(0);
        printf("from seed 0...\n");
        for(I=0;I<10;I++)
        {
            printf("randf[%d] = %1.3f\n",I,randf());
        }

        rand_seed(0);
        printf("from seed 0...\n");
        for(I=0;I<10;I++)
        {
            printf("randf[%d] = %1.3f\n",I,rand());
        }

        float q0,qlast,qmindelta,qmaxdelta,qmx,qmn,qmean,qstd,qsum,qsumsq;
        int N = 100000;
        uint32_t seed= 34533623;
        rand_seed(seed);
        printf("from seed %u...\n",seed);
        q0 = randf();
        qmx = q0;
        qmn = q0;
        qsum = 0.0f;
        qsumsq = 0.0f;
        qlast = q0;
        q0 = randf();
        qmindelta = ::fabsf(q0-qlast);
        qmaxdelta = ::fabsf(q0-qlast);
        for(I=0;I<N;I++)
        {
            qlast = q0;
            q0 = randf();

            qsum += q0;
            qsumsq += q0*q0;
            if(q0>qmx) qmx = q0;
            if(q0<qmn) qmn = q0;
            if(::fabsf(q0-qlast)<qmindelta) qmindelta = ::fabsf(q0-qlast);
            if(::fabsf(q0-qlast)>qmaxdelta) qmaxdelta = ::fabsf(q0-qlast);
        }

        qmean = qsum/((float)N);
        qstd = ::sqrtf((qsumsq-qsum*qsum/((float)N))/((float)N));

        printf("Statistics for randf() N=%d\n",N);
        printf("\tmin: %1.3g\n",qmn);
        printf("\tmax: %1.3g\n",qmx);
        printf("\tmean: %1.3g\n",qmean);
        printf("\tstdev: %1.3g\n",qstd);
        printf("\tmindelta: %1.3g\n",qmindelta);
        printf("\tmaxdelta: %1.3g\n",qmaxdelta);


        return;
    }

}; //end namespaces
};