IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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");
Note: See TracChangeset for help on using the changeset viewer.