This page will look better in a graphical browser that supports web standards, but is accessible to any browser or internet device.

Served by Samwise.

# 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

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 kd1 = 0.05 s^(-1), kd2 = 0.005 sec^(-1), kd3 = 0.001 sec^(-1);

//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 plugin required)