Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Cauchy Random Numbers

Cauchy distributed pseudorandom numbers.

Usage

var cauchy = require( '@stdlib/math/base/random/cauchy' );

cauchy( x0, gamma )

Returns a pseudorandom number drawn from a Cauchy distribution with parameters x0 (location parameter) and gamma > 0 (scale parameter).

var r = cauchy( 2.0, 5.0 );
// returns <number>

If x0 or gamma is NaN or gamma <= 0, the function returns NaN.

var r = cauchy( 2.0, -2.0 );
// returns NaN

r = cauchy( NaN, 5.0 );
// returns NaN

r = cauchy( 2.0, NaN );
// returns NaN

cauchy.factory( [x0, gamma, ][options] )

Returns a pseudorandom number generator (PRNG) for generating pseudorandom numbers drawn from a Cauchy distribution.

var rand = cauchy.factory();

var r = rand( 0.0, 1.5 );
// returns <number>

If provided x0 and gamma, the returned generator returns random variates from the specified distribution.

// Draw from Cauchy( 0.0, 1.5 ) distribution:
var rand = cauchy.factory( 0.0, 1.5 );

var r = rand();
// returns <number>

r = rand();
// returns <number>

If not provided x0 and gamma, the returned generator requires that both parameters be provided at each invocation.

var rand = cauchy.factory();

var r = rand( 0.0, 1.0 );
// returns <number>

r = rand( -2.0, 2.0 );
// returns <number>

The function accepts the following options:

  • seed: pseudorandom number generator seed.

To seed a pseudorandom number generator, set the seed option.

var rand = cauchy.factory({
    'seed': 12345
});

var r = rand( 2.0, 3.0 );
// returns <number>

rand = cauchy.factory( 2.0, 3.0, {
    'seed': 12345
});

r = rand();
// returns <number>

cauchy.NAME

The generator name.

var name = cauchy.NAME;
// returns 'cauchy'

cauchy.PRNG

The underlying pseudorandom number generator.

var prng = cauchy.PRNG;
// returns <Function>

cauchy.SEED

The value used to seed cauchy().

var rand;
var r;
var i;

// Generate pseudorandom values...
for ( i = 0; i < 100; i++ ) {
    r = cauchy( 0.0, 2.0 );
}

// Generate the same pseudorandom values...
rand = cauchy.factory( 0.0, 2.0, {
    'seed': cauchy.SEED
});
for ( i = 0; i < 100; i++ ) {
    r = rand();
}

Examples

var cauchy = require( '@stdlib/math/base/random/cauchy' );

var seed;
var rand;
var i;

// Generate pseudorandom numbers...
console.log( '\nseed: %d', cauchy.SEED );
for ( i = 0; i < 100; i++ ) {
    console.log( cauchy( 2.0, 2.0 ) );
}

// Create a new pseudorandom number generator...
seed = 1234;
rand = cauchy.factory( -6.0, 2.0, {
    'seed': seed
});
console.log( '\nseed: %d', seed );
for ( i = 0; i < 100; i++ ) {
    console.log( rand() );
}

// Create another pseudorandom number generator using a previous seed...
rand = cauchy.factory( 2.0, 2.0, {
    'seed': cauchy.SEED
});
console.log( '\nseed: %d', cauchy.SEED );
for ( i = 0; i < 100; i++ ) {
    console.log( rand() );
}