Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision 4dbf0ec391b877f21402aed9e8351fe8f7468d14 authored by D019 Rig on 19 December 2019, 23:25:22 UTC, committed by D019 Rig on 19 December 2019, 23:25:22 UTC
Update Calibration
1 parent 4cac1d4
  • Files
  • Changes
  • cb6e09d
  • /
  • Tools
  • /
  • Program_Maestro_and_CX
  • /
  • v410
  • /
  • cxdata_src_V410
  • /
  • testrng.c
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
revision badge
swh:1:rev:4dbf0ec391b877f21402aed9e8351fe8f7468d14
directory badge
swh:1:dir:7cb7f028037ea1fe6743e8c4ed8776a4befa1faa
content badge
swh:1:cnt:8248ca81422e2aa96898e0dcff269364b7453333

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
testrng.c
//===================================================================================================================== 
//
// testrng.c -- Implementation of MATLAB MEX function testrng() which tests the uniform and Gaussian random number 
//              generators underpinning Maestro's uniform and Gaussian noise perturbations.
//
// AUTHOR:  saruffner.
//
// DESCRIPTION:
//
//
// REVISION HISTORY:
// 04aug2005-- Created.
//===================================================================================================================== 

#include <stdio.h>
#include "mex.h"

#include "pertmgr.h"          // this module handles most details of processing TARGET_PERTURB trial codes

//===================================================================================================================== 
// FUNCTIONS DEFINED IN THIS MODULE
//===================================================================================================================== 
void usage();


//=== mexFunction (testrng) =========================================================================================== 
// 
//       [U, G] = testrng( N, seed, gMin, gMax )  
//       where:
//          N        ==> Number of random numbers to generate.  A scalar value, it will be rounded to nearest int.
//          seed     ==> Initial seed for generators.  Also a scalar value rounded to nearest int.  If 0, 1 is used.
//          gMin,gMax==> If a given Gaussian random # is outside [gMin,gMax), discard it. To impose range-limiting, 
//                       gMin must be < 0 and gMin > 0.
//          U        ==> A vector of length N containing the sequence of numbers generated by the uniform RNG and 
//                       scaled to the range (-1..1).
//          G        ==> An vector of length N containing the sequence of numbers generated by the Gaussian RNG, which 
//                       should have a mean of zero and a standard deviation of 1. 
//
//    ARGS:       nlhs, plhs  -- [out] array output ("left-hand side") containing data/info in the file.  If nlhs=1, 
//                               only U is prepared.  If nlhs==2, both RNG sequences are prepared.  Otherwise, the 
//                               function aborts.
//                nrhs, prhs  -- [in] array input.  See above.
//
//    RETURNS:    NONE.  If a fatal error occurs while processing the file, an error message is printed to STDOUT and 
//                a partially completed (possibly) output structure is returned.
//
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
   UNIFORMRNG urng;                                            // state info for the two RNGs
   GAUSSRNG grng;
   int n;
   int nIterations;                                            // number of random #s to generate from each RNG
   int seed;                                                   // the initial seed for both RNGs
   double dGaussMin;                                           // range limits on Gaussian RNG sequence
   double dGaussMax;
   double dNext;
   BOOL bRangeLimit;                                           // TRUE if range limits are imposed.
   double* pdUniformSeq;                                       // our two sequences
   double* pdGaussSeq;

   if( nrhs != 4 || nlhs < 1 || nlhs > 2 )                     // get args
   {
      usage();
      return;
   }
   nIterations = (int) *mxGetPr(prhs[0]);
   if( nIterations < 0 ) nIterations = 0;
   seed = (int) *mxGetPr(prhs[1]);
   dGaussMin = *mxGetPr(prhs[2]);
   dGaussMax = *mxGetPr(prhs[3]);
   bRangeLimit = (BOOL) (dGaussMin < 0.0 && dGaussMax > 0.0);

   plhs[0] = mxCreateDoubleMatrix(1, nIterations, mxREAL );    // create one or both output vectors
   pdUniformSeq = mxGetPr( plhs[0] );
   if( nlhs == 2 )
   {
      plhs[1] = mxCreateDoubleMatrix(1, nIterations, mxREAL);
      pdGaussSeq = mxGetPr( plhs[1] );
   }
   else
      pdGaussSeq = NULL;

   seedUniformRNG( &urng, seed );                              // set initial seed on both RNGs
   seedGaussRNG( &grng, seed );

   for( n = 0; n < nIterations; n++ )                          // generate the sequences
   {
      pdUniformSeq[n] = 2.0 * getUniformRNG( &urng ) - 1.0;    //    U(0..1) --> U(-1..1)
      if( pdGaussSeq != NULL )                                 //    N(0,1), possibly range-limited
      {
         pdGaussSeq[n] = getGaussRNG( &grng );
         if( bRangeLimit )
         {
            while( pdGaussSeq[n] < dGaussMin || pdGaussSeq[n] >= dGaussMax )
               pdGaussSeq[n] = getGaussRNG( &grng );
         }
      }
   }
}

//=== usage =========================================================================================================== 
//
//    Prints testrng() usage details to STDOUT.
//
void usage()
{
  printf( "USAGE: [U, G] = testrng( n, seed ) \n" );
  printf( "   n        ==> Number of random numbers to generate. \n" );
  printf( "   seed     ==> Initial seed for generators. \n" );
}
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API