random() and randomg() pseudo-random number generators

This document describes the syntax and use of the random() and randomg() pseudo-random number generators. (MML).

Prerequisites:

Contents:

  • random() syntax
  • randomg() syntax
  • random() and randomg() examples
  • Comments or Questions?
    Give feedback

random() syntax

The random() function generates a pseudo-random number from a uniform distribution between 0 and 1 inclusive.

Syntax for generating a real number between 0 and 10:

      real var, var2;
      var=10; 
      var2 = var*random(); 

To set 'seed' value for random number generation:

  • Compile model and then go to 'Run Time' page.
  • Then chose 'Pages' -> 'Solvers'. The page should have 'Random number generator' listed.
  • A seed of '0' generates a different set of random numbers each time the model is run. A non-zero seed will generate the same 'random' numbers each time model is run.

randomg() syntax

The randomg() function generates a pseudo-random number from a Gaussian (normal) distribution of mean 0 and standard deviation 1.

Syntax for generating a real number between 0 and 10:

      real var, var2;
      var=10; 
      var2 = var*randomg(); 

random() and randomg() examples:

import nsrunit; unit conversion on;
math threeExponentials { 

// INDEPENDENT VARIABLE
realDomain t s; t.min=1; t.max=1001; t.delta=1;

// Generate CLEAN DATA:  
real CleanCurve(t) dimensionless;
real Ad1 = 1.00, Ad2 = 0.5, Ad3 = 0.25;
real kd1 = 0.05 s^(-1), kd2 = 0.005 sec^(-1), kd3 = 0.001 sec^(-1);
CleanCurve = (Ad1*exp(-kd1*t)+Ad2*exp(-kd2*t)+Ad3*exp(-kd3*t));

//Generate NOISY DATA: 5% Gaussian noise (NoiseLevel=0.05)
real NoiseLevel=0.05;
real NoisyCurve(t) = CleanCurve*(1 + NoiseLevel*randomg()); // <--- randomg()

//Generate NOISY DATA: 5% uniform noise (NoiseLevel=0.05)
real NoisyCurve2(t) = CleanCurve*(1 + NoiseLevel*random()); // <--- random()

/* To set 'seed' value for random number generation:
   - Compile model and then go to 'Run Time' page.
   - Then chose 'Pages' -> 'Solvers'
   - A seed of '0' generates a different set of random numbers each time the model is run.
     A non-zero seed will generate the same 'random' numbers each time model is run.
*/
}

 (Java required)

Comments or Questions?

Give feedback

Model development and archiving support at https://www.imagwiki.nibib.nih.gov/physiome provided by the following grants: NIH U01HL122199 Analyzing the Cardiac Power Grid, 09/15/2015 - 05/31/2020, NIH/NIBIB BE08407 Software Integration, JSim and SBW 6/1/09-5/31/13; NIH/NHLBI T15 HL88516-01 Modeling for Heart, Lung and Blood: From Cell to Organ, 4/1/07-3/31/11; NSF BES-0506477 Adaptive Multi-Scale Model Simulation, 8/15/05-7/31/08; NIH/NHLBI R01 HL073598 Core 3: 3D Imaging and Computer Modeling of the Respiratory Tract, 9/1/04-8/31/09; as well as prior support from NIH/NCRR P41 RR01243 Simulation Resource in Circulatory Mass Transport and Exchange, 12/1/1980-11/30/01 and NIH/NIBIB R01 EB001973 JSim: A Simulation Analysis Platform, 3/1/02-2/28/07.