IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23259 for trunk/psLib


Ignore:
Timestamp:
Mar 10, 2009, 4:53:42 PM (17 years ago)
Author:
Paul Price
Message:

Changing API for psRandomAlloc() to make it easier to be deterministic. psRandomAlloc() now takes only a single argument, which is the generator type (only PS_RANDOM_TAUS is currently supported; others could easily be added). The seed used by the generator is set by psRandomSeed(). This allows us to use the same seed for the random number generator over multiple calls, which means that we can be deterministic by setting the seed. The old API for psRandomAlloc() is available using psRandomAllocSpecific(). Added to the configuration setup in psModules to include recording the random seed, and setting if desired. Updated all our products to use this API. Some fixes and updates to the configuration run-time information dumping. ppImage now dumps the configuration at the end, allowing the list of files in the run-time information to be set.

Location:
trunk/psLib
Files:
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/fits/psFitsScale.c

    r21183 r23259  
    112112    // psImageBackground automatically excludes pixels that are non-finite, so we don't need to bother about a
    113113    // mask.
    114     psU64 seed = p_psRandomGetSystemSeed(false);
    115     psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, seed);
     114    psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS);
    116115    psStats *stats = psStatsAlloc(MEAN_STAT | STDEV_STAT); // Statistics object
    117116    if (!psImageBackground(stats, NULL, image, mask, maskVal, rng)) {
     
    290289    if (!psMemIncrRefCounter(rng) && options->fuzz) {
    291290        // Don't blab about which seed we're going to get --- it's not necessary for this purpose
    292         psU64 seed = p_psRandomGetSystemSeed(false);
    293         rng = psRandomAlloc(PS_RANDOM_TAUS, seed);
     291        rng = psRandomAlloc(PS_RANDOM_TAUS);
    294292    }
    295293
  • trunk/psLib/src/math/psRandom.c

    r20547 r23259  
    2929#include <inttypes.h>
    3030
     31#include "psAbort.h"
    3132#include "psMemory.h"
    3233#include "psRandom.h"
     
    3839
    3940
     41unsigned long seed = 0;                 // Seed for RNG
     42
     43
    4044psU64 p_psRandomGetSystemSeed(bool log)
    4145{
    42     FILE*  fd;
    43     psU64  seedVal = 0;
    44     time_t timeVal;
     46    psU64 seedVal = 0;                  // Seed value to return
    4547
    46     fd = fopen("/dev/urandom","r");
    47     if(fd == NULL) {
    48         // Read system clock to get seed
    49         seedVal = (psU64)time(&timeVal);
    50     } else {
    51         // Read urandom to get seed
    52         if (fread(&seedVal, sizeof(psU64),1,fd)) {;} // ignore return value
    53         // Close file
    54         fclose(fd);
     48    // Since zero is a special value in our context, don't allow the final value chosen to be zero
     49    while (seedVal == 0) {
     50        FILE *fd = fopen("/dev/urandom", "r");
     51        if (fd) {
     52            // Read urandom to get seed
     53            if (fread(&seedVal, sizeof(psU64), 1, fd)) {;} // ignore return value
     54            // Close file
     55            fclose(fd);
     56        } else {
     57            // Read system clock to get seed
     58            time_t timeVal;                 // Time value
     59            seedVal = (psU64)time(&timeVal);
     60        }
    5561    }
    5662
     
    6369}
    6470
    65 psRandom *psRandomAlloc(psRandomType type,
    66                         unsigned long seed)
     71psU64 psRandomSeed(psU64 value)
    6772{
    68     gsl_rng   *r      = NULL;
    69     psRandom  *myRNG  = NULL;
     73    while (value == 0) {
     74        value = p_psRandomGetSystemSeed(true);
     75    }
     76    seed = value;
     77    return seed;
     78}
    7079
     80// Destructor for psRandom
     81static void randomFree(psRandom *rng)
     82{
     83    if (rng->gsl) {
     84        gsl_rng_free(rng->gsl);
     85    }
     86    return;
     87}
     88
     89// Constructor for psRandom
     90static psRandom *randomAlloc(psRandomType type)
     91{
     92    psRandom *rng = psAlloc(sizeof(psRandom)); // Random number generator to return
     93    psMemSetDeallocator(rng, (psFreeFunc)randomFree);
     94
     95    rng->type = type;
     96
     97    const gsl_rng_type *gslType;        // Type of RNG according to GSL
    7198    switch (type) {
    72     case PS_RANDOM_TAUS:
    73         myRNG = (psRandom*)psAlloc(sizeof(psRandom));
    74         r = gsl_rng_alloc(gsl_rng_taus);
    75         myRNG->gsl = r;
    76         if(seed == 0) {
    77             gsl_rng_set(myRNG->gsl, p_psRandomGetSystemSeed(true));
    78         } else {
    79             gsl_rng_set(myRNG->gsl, seed);
    80         }
    81         myRNG->type = type;
     99      case PS_RANDOM_TAUS:
     100        gslType = gsl_rng_taus;
    82101        break;
    83 
    84     default:
    85         psError(PS_ERR_UNEXPECTED_NULL, true, _("Unknown Random Number Generator Type"));
     102      default:
     103        psAbort("Unknown Random Number Generator Type: %x", type);
    86104        break;
    87105    }
    88106
    89     return(myRNG);
     107    rng->gsl = gsl_rng_alloc(gslType);
     108    return rng;
    90109}
    91110
    92 void psRandomReset(psRandom *rand,
    93                    unsigned long seed)
     111psRandom *psRandomAlloc(psRandomType type)
    94112{
    95     // Check null psRandom
    96     if(rand==NULL) {
    97         psError(PS_ERR_UNEXPECTED_NULL,
    98                 true,
    99                 _("Random variable is NULL."));
    100     } else {
    101         // Check seed value to see if system seed should be used
    102         if(seed == 0) {
    103             gsl_rng_set(rand->gsl,p_psRandomGetSystemSeed(true));
    104         } else {
    105             gsl_rng_set(rand->gsl, seed);
    106         }
     113    psRandom *rng = randomAlloc(type);
     114    psRandomReset(rng);
     115
     116    return rng;
     117}
     118
     119psRandom *psRandomAllocSpecific(psRandomType type, psU64 specificSeed)
     120{
     121    psRandom *rng = randomAlloc(type);
     122    if (specificSeed == 0) {
     123        specificSeed = p_psRandomGetSystemSeed(true);
    107124    }
     125    gsl_rng_set(rng->gsl, specificSeed);
     126    return rng;
     127}
     128
     129bool psRandomReset(psRandom *rand)
     130{
     131    PS_ASSERT_RANDOM_NON_NULL(rand, false);
     132    if (seed == 0) {
     133        seed = p_psRandomGetSystemSeed(true);
     134    }
     135    gsl_rng_set(rand->gsl, seed);
     136    return true;
    108137}
    109138
    110139double psRandomUniform(const psRandom *r)
    111140{
    112     // Check null psRandom variable
    113     if(r == NULL) {
    114         psError(PS_ERR_UNEXPECTED_NULL,
    115                 true,
    116                 _("Random variable is NULL."));
    117         return(0);
    118     } else {
    119         return(gsl_rng_uniform(r->gsl));
    120     }
     141    PS_ASSERT_RANDOM_NON_NULL(r, NAN);
     142    return gsl_rng_uniform(r->gsl);
    121143}
    122144
    123145double psRandomGaussian(const psRandom *r)
    124146{
    125     // Check null psRandom variable
    126     if(r == NULL) {
    127         psError(PS_ERR_UNEXPECTED_NULL,
    128                 true,
    129                 _("Random variable is NULL."));
    130         return(0);
    131     } else {
    132         // XXX: What should sigma be?
    133         return(gsl_ran_gaussian(r->gsl, 1.0));
    134     }
     147    PS_ASSERT_RANDOM_NON_NULL(r, NAN);
     148    return gsl_ran_gaussian(r->gsl, 1.0);
    135149}
    136150
    137151double p_psRandomGaussian(const psRandom *r, double sigma)
    138152{
    139     // Check null psRandom variable
    140     if(r == NULL) {
    141         psError(PS_ERR_UNEXPECTED_NULL,
    142                 true,
    143                 _("Random variable is NULL."));
    144         return(0);
    145     } else {
    146         return(gsl_ran_gaussian(r->gsl, sigma));
    147     }
     153    PS_ASSERT_RANDOM_NON_NULL(r, NAN);
     154    return gsl_ran_gaussian(r->gsl, sigma);
    148155}
    149156
    150157double psRandomPoisson(const psRandom *r, double mean)
    151158{
    152     // Check null psRandom variable
    153     if(r == NULL) {
    154         psError(PS_ERR_UNEXPECTED_NULL,
    155                 true,
    156                 _("Random variable is NULL."));
    157         return(0);
    158     } else {
    159         return((psF64) gsl_ran_poisson(r->gsl, mean));
    160     }
     159    PS_ASSERT_RANDOM_NON_NULL(r, NAN);
     160    return gsl_ran_poisson(r->gsl, mean);
    161161}
    162162
  • trunk/psLib/src/math/psRandom.h

    r15627 r23259  
    2929#include <gsl/gsl_randist.h>
    3030
    31 /** Enumeration containing a flag for psRandom types.  */
     31/// Random number generator types
    3232typedef enum {
    3333    PS_RANDOM_TAUS                     ///< A maximally equidistributed combined Tausworthe generator.
    3434} psRandomType;
    3535
    36 /** Data structure for psRandom.
    37  *  Contains information on the psRandom type and GNU Scientific Library random number generator.
    38  */
     36/// Random number generator
    3937typedef struct {
    4038    psRandomType type;                 ///< The type of RNG
     
    4846    );
    4947
    50 /** Allocates a psRandom struct.
    51  *
    52  *  @return psRandom*:    A new psRandom structure.
    53  */
     48/// Set the seed to use for random number generators.
     49///
     50/// A seed value of zero indicates that the seed is to be generated from the system.
     51/// The new seed value is returned
     52psU64 psRandomSeed(psU64 seed           ///< Seed for RNG
     53                   );
     54
     55/// Allocate a random number generator
     56///
     57/// The currently defined seed (via psRandomSeed) is used
    5458psRandom *psRandomAlloc(
    55     psRandomType type,                 ///< The type of RNG
    56     unsigned long seed                 ///< Known value with which to seed the RNG
     59    psRandomType type                   ///< The type of RNG
    5760) PS_ATTR_MALLOC;
    5861
    59 /** Resets an existing psRandom struct.
    60  *
    61  *  @return void
    62  */
    63 void psRandomReset(
    64     psRandom *rand,                    ///< Existing psRandom struct to reset
    65     unsigned long seed                 ///< Known value with which to seed the RNG
     62/// Allocate a random number generator with a specific seed
     63///
     64/// A seed value of zero indicates that the seed is to be generated from the system.
     65psRandom *psRandomAllocSpecific(psRandomType type, ///< The type of RNG
     66                                psU64 specificSeed ///< The specific seed to use
     67    );
     68
     69/// Resets an existing random number generator
     70bool psRandomReset(
     71    psRandom *rand                      ///< Random number generator to reset
    6672);
    6773
     
    7278 */
    7379double psRandomUniform(
    74     const psRandom *r                  ///< psRandom struct for RNG
     80    const psRandom *r                  ///< Random number generator
    7581);
    7682
     
    8187 */
    8288double psRandomGaussian(
    83     const psRandom *r                  ///< psRandom struct for RNG
     89    const psRandom *r                  ///< Random number generator
    8490);
    8591
    86 /** Random number generator based on a Gaussian deviate, N(0,1).
     92/** Random number generator based on a Gaussian deviate with specified standard deviation.
    8793 *  Uses gsl_ran_gaussian.
    88  *
    89  *  XXX: I created this since the above psLib spec for p_psRandomGaussian
    90  *  had no argument for sigma.  Verify that with IfA.
    9194 *
    9295 *  @return double:     Random number.
    9396 */
    9497double p_psRandomGaussian(
    95     const psRandom *r,                  ///< psRandom struct for RNG
     98    const psRandom *r,                  ///< Random number generator
    9699    double sigma
    97100);
     
    103106 */
    104107double psRandomPoisson(
    105     const psRandom *r,                 ///< psRandom struct for RNG
     108    const psRandom *r,                  ///< Random number generator
    106109    double mean                         ///< Mean value
    107110);
  • trunk/psLib/test/fits/tap_psFitsImage.c

    r19382 r23259  
    1212static psImage *generateImage(void)
    1313{
    14     psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 12345); // Random number generator
     14    psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 12345); // Random number generator
    1515    psImage *image = psImageAlloc(NUMCOLS, NUMROWS, PS_TYPE_F32); // Generated image
    1616    for (int y = 0; y < NUMROWS; y++) {
  • trunk/psLib/test/imageops/convolutionBench.c

    r17320 r23259  
    6868int main(int argc, char *argv[])
    6969{
    70     psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0); // Random number generator
     70    psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 0); // Random number generator
    7171
    7272    printf("#%14s%16s        %8s        %8s\n", "Image", "Kernel", "Direct", "FFT");
  • trunk/psLib/test/imageops/tap_psImageInterpolate2.c

    r21465 r23259  
    7777    psImage *variance = NULL; // generateVariance(xSize, ySize, type);
    7878    psImage *mask = NULL; // generateMask(xSize, ySize);
    79     psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 12345);
     79    psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 12345);
    8080
    8181    psImageInterpolation *interp = psImageInterpolationAlloc(mode, image, variance, mask, 0, NAN, NAN,
  • trunk/psLib/test/math/tap_psMinimizeLMM.c

    r13124 r23259  
    9595    {
    9696        psMemId id = psMemGetId();
    97         psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 1); // Random number generator; using known seed
     97        psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 1); // Random number generator; using known seed
    9898        psMinimization *min = psMinimizationAlloc(NUM_ITERATIONS, ERR_TOL);
    9999        psArray *ordinates = psArrayAlloc(NUM_DATA_POINTS);
     
    203203    {
    204204        psMemId id = psMemGetId();
    205         psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 1); // Random number generator; using known seed
     205        psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 1); // Random number generator; using known seed
    206206        psMinimization *min = psMinimizationAlloc(NUM_ITERATIONS, ERR_TOL);
    207207        psArray *ordinates = psArrayAlloc(NUM_DATA_POINTS);
  • trunk/psLib/test/math/tap_psPolyFit1D.c

    r13337 r23259  
    109109    psVector *xTruth = psVectorAlloc(numData, PS_TYPE_F64);
    110110    psVector *fTruth = psVectorAlloc(numData, PS_TYPE_F64);
    111     psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 1); // Using a known seed
     111    psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 1); // Using a known seed
    112112    for (int i = 0; i < numData; i++) {
    113113        xTruth->data.F64[i] = (flags & TS00_X_NULL) ? i : 2.0*psRandomUniform(rng) - 1.0;
  • trunk/psLib/test/math/tap_psPolyFit2D.c

    r17567 r23259  
    108108    yTruth->n = numData;
    109109    fTruth->n = numData;
    110     psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 1); // Using an RNG with a known seed
     110    psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 1); // Using an RNG with a known seed
    111111    for (int i = 0; i < numData; i++) {
    112112        xTruth->data.F64[i] = 2.0*psRandomUniform(rng) - 1.0;
  • trunk/psLib/test/math/tap_psPolyFit3D.c

    r17567 r23259  
    108108    zTruth->n = numData;
    109109    fTruth->n = numData;
    110     psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 1); // Using known seed
     110    psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 1); // Using known seed
    111111    for (int i = 0; i < numData; i++) {
    112112        xTruth->data.F64[i] = 2.0*psRandomUniform(rng) - 1.0;
  • trunk/psLib/test/math/tap_psPolyFit4D.c

    r17567 r23259  
    132132    tTruth->n = numData;
    133133    fTruth->n = numData;
    134     psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 1); // Using known seed
     134    psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 1); // Using known seed
    135135    for (int i = 0; i < numData; i++) {
    136136        xTruth->data.F64[i] = 2.0*psRandomUniform(rng) - 1.0;
  • trunk/psLib/test/math/tap_psRandom.c

    r13123 r23259  
    33work properly.
    44 
    5     ensure that psRandom structs are properly allocated by psRandomAlloc().
     5    ensure that psRandom structs are properly allocated by psRandomAllocSpecific().
    66    ensure that psRandomUniform() produces a sequence of numbers with
    77        proper mean and stdev.
     
    4747    plan_tests(34);
    4848
    49     // ensure that psRandom structs are properly allocated by psRandomAlloc()
     49    // ensure that psRandom structs are properly allocated by psRandomAllocSpecific()
    5050    {
    5151        psMemId id = psMemGetId();
    5252        // Valid type allocation
    53         psRandom *myRNG = psRandomAlloc(PS_RANDOM_TAUS, SEED);
    54         ok(myRNG != NULL, "psRandom struct was allocated properly");
    55         skip_start(myRNG == NULL, 1, "Skipping tests because psRandomAlloc() failed");
    56         ok(myRNG->type == PS_RANDOM_TAUS, "psRandomAlloc() set type properly");
     53        psRandom *myRNG = psRandomAllocSpecific(PS_RANDOM_TAUS, SEED);
     54        ok(myRNG != NULL, "psRandom struct was allocated properly");
     55        skip_start(myRNG == NULL, 1, "Skipping tests because psRandomAllocSpecific() failed");
     56        ok(myRNG->type == PS_RANDOM_TAUS, "psRandomAllocSpecific() set type properly");
    5757        psFree(myRNG);
    5858        skip_end();
     
    6363    {
    6464        psMemId id = psMemGetId();
    65         psRandom *myRNG = psRandomAlloc(100,SEED);
    66         ok(myRNG == NULL, "psRandomAlloc() refused to generate psRandom with unallowed type");
     65        psRandom *myRNG = psRandomAllocSpecific(100,SEED);
     66        ok(myRNG == NULL, "psRandomAllocSpecific() refused to generate psRandom with unallowed type");
    6767        psFree(myRNG);
    6868        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     
    7272    {
    7373        psMemId id = psMemGetId();
    74         psRandom *myRNG = psRandomAlloc(PS_RANDOM_TAUS,-5);
    75         ok(myRNG != NULL, "psRandomAlloc() allows negative seed");
     74        psRandom *myRNG = psRandomAllocSpecific(PS_RANDOM_TAUS,-5);
     75        ok(myRNG != NULL, "psRandomAllocSpecific() allows negative seed");
    7676        psFree(myRNG);
    7777        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     
    8585        rans->n = rans->nalloc;
    8686        psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
    87         psRandom *myRNG = psRandomAlloc(PS_RANDOM_TAUS, SEED);
    88         ok(myRNG != NULL, "psRandom struct was allocated properly");
    89         skip_start(myRNG == NULL, 2, "Skipping tests because psRandomAlloc() failed");
     87        psRandom *myRNG = psRandomAllocSpecific(PS_RANDOM_TAUS, SEED);
     88        ok(myRNG != NULL, "psRandom struct was allocated properly");
     89        skip_start(myRNG == NULL, 2, "Skipping tests because psRandomAllocSpecific() failed");
    9090
    9191        // Initialize vector data with random number
     
    125125        rans->n = rans->nalloc;
    126126        psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
    127         psRandom *myRNG = psRandomAlloc(PS_RANDOM_TAUS, SEED);
    128         ok(myRNG != NULL, "psRandom struct was allocated properly");
    129         skip_start(myRNG == NULL, 2, "Skipping tests because psRandomAlloc() failed");
     127        psRandom *myRNG = psRandomAllocSpecific(PS_RANDOM_TAUS, SEED);
     128        ok(myRNG != NULL, "psRandom struct was allocated properly");
     129        skip_start(myRNG == NULL, 2, "Skipping tests because psRandomAllocSpecific() failed");
    130130
    131131        // Initialize vector with random data
     
    167167        rans->n = rans->nalloc;
    168168        psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
    169         psRandom *myRNG = psRandomAlloc(PS_RANDOM_TAUS, SEED);
    170         ok(myRNG != NULL, "psRandom struct was allocated properly");
    171         skip_start(myRNG == NULL, 2, "Skipping tests because psRandomAlloc() failed");
     169        psRandom *myRNG = psRandomAllocSpecific(PS_RANDOM_TAUS, SEED);
     170        ok(myRNG != NULL, "psRandom struct was allocated properly");
     171        skip_start(myRNG == NULL, 2, "Skipping tests because psRandomAllocSpecific() failed");
    172172
    173173        // Initialize vector with random data
     
    210210        rans02->n = rans02->nalloc;
    211211
    212         psRandom *myRNG = psRandomAlloc(PS_RANDOM_TAUS, SEED);
    213         ok(myRNG != NULL, "psRandom struct was allocated properly");
    214         skip_start(myRNG == NULL, 1, "Skipping tests because psRandomAlloc() failed");
     212        psRandom *myRNG = psRandomAllocSpecific(PS_RANDOM_TAUS, SEED);
     213        ok(myRNG != NULL, "psRandom struct was allocated properly");
     214        skip_start(myRNG == NULL, 1, "Skipping tests because psRandomAllocSpecific() failed");
    215215
    216216
     
    252252    if (0) {
    253253        psRandom *myRNG1 = NULL;
    254         myRNG1 = psRandomAlloc(PS_RANDOM_TAUS, SEED);
     254        myRNG1 = psRandomAllocSpecific(PS_RANDOM_TAUS, SEED);
    255255        //    psLogSetDestination("dest:stderr");
    256256        psLogSetDestination(0);
     
    275275        rans02->n = rans02->nalloc;
    276276
    277         psRandom *myRNG = psRandomAlloc(PS_RANDOM_TAUS, SEED);
    278         ok(myRNG != NULL, "psRandom struct was allocated properly");
    279         skip_start(myRNG == NULL, 1, "Skipping tests because psRandomAlloc() failed");
     277        psRandom *myRNG = psRandomAllocSpecific(PS_RANDOM_TAUS, SEED);
     278        ok(myRNG != NULL, "psRandom struct was allocated properly");
     279        skip_start(myRNG == NULL, 1, "Skipping tests because psRandomAllocSpecific() failed");
    280280
    281281
     
    325325        rans02->n = rans02->nalloc;
    326326
    327         psRandom *myRNG = psRandomAlloc(PS_RANDOM_TAUS, SEED);
    328         ok(myRNG != NULL, "psRandom struct was allocated properly");
    329         skip_start(myRNG == NULL, 1, "Skipping tests because psRandomAlloc() failed");
     327        psRandom *myRNG = psRandomAllocSpecific(PS_RANDOM_TAUS, SEED);
     328        ok(myRNG != NULL, "psRandom struct was allocated properly");
     329        skip_start(myRNG == NULL, 1, "Skipping tests because psRandomAllocSpecific() failed");
    330330
    331331        // Initialize vectors with random data
  • trunk/psLib/test/math/tap_psStats07.c

    r12247 r23259  
    5858    PS_ASSERT_INT_NONNEGATIVE(Npts, NULL);
    5959
    60     //    psRandom *r = psRandomAlloc(PS_RANDOM_TAUS, p_psRandomGetSystemSeed());
    61     psRandom *r = psRandomAlloc(PS_RANDOM_TAUS, PS_XXX_GAUSSIAN_SEED);
     60    //    psRandom *r = psRandomAllocSpecific(PS_RANDOM_TAUS, p_psRandomGetSystemSeed());
     61    psRandom *r = psRandomAllocSpecific(PS_RANDOM_TAUS, PS_XXX_GAUSSIAN_SEED);
    6262    psVector* gauss = psVectorAlloc(Npts, PS_TYPE_F32);
    6363    for (unsigned int i = 0; i < Npts; i++) {
  • trunk/psLib/test/math/tap_psStats09.c

    r12783 r23259  
    5252    srand(SEED);
    5353
    54     psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 1); // Random number generator; using known seed
     54    psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 1); // Random number generator; using known seed
    5555    psVector *truth = psVectorAlloc(numData, PS_TYPE_F64);
    5656    for (long i = 0; i < numData; i++) {
  • trunk/psLib/test/math/tap_psStatsTiming.c

    r12513 r23259  
    2020
    2121    // build a gauss-deviate vector (mean = 0.0, sigma = 1.0) for tests
    22     psRandom *seed = psRandomAlloc (PS_RANDOM_TAUS, 0);
     22    psRandom *seed = psRandomAllocSpecific (PS_RANDOM_TAUS, 0);
    2323    psVector *rnd = psVectorAlloc (1000, PS_TYPE_F32);
    2424    for (int i = 0; i < rnd->n; i++) {
  • trunk/psLib/test/math/tst_psMinimizeLMM.c

    r11686 r23259  
    6666    psBool testStatus = true;
    6767
    68     psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 1); // Random number generator; using known seed
     68    psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 1); // Random number generator; using known seed
    6969    psMinimization *min = psMinimizationAlloc(NUM_ITERATIONS, ERR_TOL);
    7070    psArray *ordinates = psArrayAlloc(NUM_DATA_POINTS);
  • trunk/psLib/test/math/tst_psPolyFit1D.c

    r11686 r23259  
    101101    xTruth->n = numData;
    102102    fTruth->n = numData;
    103     psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 1); // Using a known seed
     103    psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 1); // Using a known seed
    104104    for (int i = 0; i < numData; i++) {
    105105        xTruth->data.F64[i] = (flags & TS00_X_NULL) ? i : 2.0*psRandomUniform(rng) - 1.0;
  • trunk/psLib/test/math/tst_psPolyFit2D.c

    r11686 r23259  
    100100    yTruth->n = numData;
    101101    fTruth->n = numData;
    102     psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 1); // Using an RNG with a known seed
     102    psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 1); // Using an RNG with a known seed
    103103    for (int i = 0; i < numData; i++) {
    104104        xTruth->data.F64[i] = 2.0*psRandomUniform(rng) - 1.0;
  • trunk/psLib/test/math/tst_psPolyFit3D.c

    r11686 r23259  
    103103    zTruth->n = numData;
    104104    fTruth->n = numData;
    105     psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 1); // Using known seed
     105    psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 1); // Using known seed
    106106    for (int i = 0; i < numData; i++) {
    107107        xTruth->data.F64[i] = 2.0*psRandomUniform(rng) - 1.0;
  • trunk/psLib/test/math/tst_psPolyFit4D.c

    r11686 r23259  
    124124    tTruth->n = numData;
    125125    fTruth->n = numData;
    126     psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 1); // Using known seed
     126    psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 1); // Using known seed
    127127    for (int i = 0; i < numData; i++) {
    128128        xTruth->data.F64[i] = 2.0*psRandomUniform(rng) - 1.0;
  • trunk/psLib/test/math/tst_psRandom.c

    r6484 r23259  
    33work properly.
    44 
    5     t00(): ensure that psRandom structs are properly allocated by psRandomAlloc().
     5    t00(): ensure that psRandom structs are properly allocated by psRandomAllocSpecific().
    66    t01(): ensure that psRandomUniform() produces a sequence of numbers with
    77    proper mean and stdev.
     
    4545
    4646testDescription tests[] = {
    47                               {testRandomAlloc,000,"psRandomAlloc",0,false},
     47                              {testRandomAlloc,000,"psRandomAllocSpecific",0,false},
    4848                              {testRandomUniform,000,"psRandomUniform",0,false},
    4949                              {testRandomGaussian,000,"psRandomGaussian",0,false},
     
    7070
    7171    // Valid type allocation
    72     myRNG = psRandomAlloc(PS_RANDOM_TAUS, SEED);
     72    myRNG = psRandomAllocSpecific(PS_RANDOM_TAUS, SEED);
    7373    if (myRNG == NULL) {
    7474        psError(PS_ERR_UNKNOWN,true,"Could not allocate psRandom structure");
     
    8585    //    psLogSetDestination("file:seed_msglog1.txt");
    8686    psLogSetDestination(fd1);
    87     myRNG = psRandomAlloc(PS_RANDOM_TAUS, 0);
     87    myRNG = psRandomAllocSpecific(PS_RANDOM_TAUS, 0);
    8888    //    psLogSetDestination("dest:stderr");
    8989    psLogSetDestination(2);
     
    100100    // Invalid type allocation
    101101    psLogMsg(__func__,PS_LOG_INFO,"Invalid type, should generate error message");
    102     myRNG = psRandomAlloc(100,SEED);
     102    myRNG = psRandomAllocSpecific(100,SEED);
    103103    if (myRNG != NULL) {
    104104        psError(PS_ERR_UNKNOWN,true,"Did not return NULL for invalid type");
     
    107107
    108108    // Negative seed value
    109     myRNG = psRandomAlloc(PS_RANDOM_TAUS,-5);
     109    myRNG = psRandomAllocSpecific(PS_RANDOM_TAUS,-5);
    110110    if(myRNG == NULL) {
    111111        psError(PS_ERR_UNKNOWN,true,"Did not return allocated psRandom");
     
    125125    psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
    126126
    127     myRNG = psRandomAlloc(PS_RANDOM_TAUS, SEED);
     127    myRNG = psRandomAllocSpecific(PS_RANDOM_TAUS, SEED);
    128128    if (myRNG == NULL) {
    129129        psError(PS_ERR_UNKNOWN,true,"Could not allocate psRandom structure");
     
    171171    psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
    172172
    173     myRNG = psRandomAlloc(PS_RANDOM_TAUS, SEED);
     173    myRNG = psRandomAllocSpecific(PS_RANDOM_TAUS, SEED);
    174174    if (myRNG == NULL) {
    175175        psError(PS_ERR_UNKNOWN,true,"Could not allocate psRandom structure");
     
    219219    psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
    220220
    221     myRNG = psRandomAlloc(PS_RANDOM_TAUS, SEED);
     221    myRNG = psRandomAllocSpecific(PS_RANDOM_TAUS, SEED);
    222222    if (myRNG == NULL) {
    223223        psError(PS_ERR_UNKNOWN,true,"Could not allocate psRandom structure");
     
    268268    rans02->n = rans02->nalloc;
    269269
    270     myRNG = psRandomAlloc(PS_RANDOM_TAUS, SEED);
     270    myRNG = psRandomAllocSpecific(PS_RANDOM_TAUS, SEED);
    271271    if (myRNG == NULL) {
    272272        psError(PS_ERR_UNKNOWN,true,"Could not allocate psRandom structure");
     
    302302
    303303    psRandom *myRNG1 = NULL;
    304     myRNG1 = psRandomAlloc(PS_RANDOM_TAUS, SEED);
     304    myRNG1 = psRandomAllocSpecific(PS_RANDOM_TAUS, SEED);
    305305    //    psLogSetDestination("dest:stderr");
    306306    psLogSetDestination(0);
     
    326326    rans02->n = rans02->nalloc;
    327327
    328     myRNG = psRandomAlloc(PS_RANDOM_TAUS, SEED);
     328    myRNG = psRandomAllocSpecific(PS_RANDOM_TAUS, SEED);
    329329    if (myRNG == NULL) {
    330330        psError(PS_ERR_UNKNOWN,true,"Could not allocate psRandom structure");
     
    372372    rans02->n = rans02->nalloc;
    373373
    374     myRNG = psRandomAlloc(PS_RANDOM_TAUS, SEED);
     374    myRNG = psRandomAllocSpecific(PS_RANDOM_TAUS, SEED);
    375375    if (myRNG == NULL) {
    376376        psError(PS_ERR_UNKNOWN,true,"Could not allocate psRandom structure");
  • trunk/psLib/test/math/tst_psStats09.c

    r11686 r23259  
    5252    printPositiveTestHeader(stdout, "psMathUtils functions", "psVectorStats Clipped Stats Routine");
    5353
    54     psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 1); // Random number generator; using known seed
     54    psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 1); // Random number generator; using known seed
    5555    psVector *truth = psVectorAlloc(numData, PS_TYPE_F64);
    5656    truth->n = numData;
  • trunk/psLib/test/mathtypes/tap_psVectorSelect.c

    r18333 r23259  
    1717    psVector *vector = psVectorAlloc(size, PS_TYPE_F32);
    1818    psVectorInit(vector, 0.0);
    19     psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 12345);
     19    psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 12345);
    2020    for (long i = 0; i < numNonzero; i++) {
    2121        long index = psRandomUniform(rng) * size;
     
    5252    psVector *vector = psVectorAlloc(size, PS_TYPE_F32);
    5353    psVectorInit(vector, 0.0);
    54     psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 12345);
     54    psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 12345);
    5555    for (long i = 0; i < numNonzero; i++) {
    5656        long index = psRandomUniform(rng) * size;
  • trunk/psLib/test/types/tap_psTree.c

    r18145 r23259  
    1616        psVector *y = psVectorAlloc(NUM, PS_TYPE_F64);
    1717
    18         psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0);
     18        psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 0);
    1919        for (int i = 0; i < NUM; i++) {
    2020            x->data.F64[i] = 2.0 * psRandomUniform(rng) - 1.0;
Note: See TracChangeset for help on using the changeset viewer.