Raised Cosine Random Numbers

Raised cosine distributed pseudorandom numbers.

Usage

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

cosine( mu, s )

Returns a pseudorandom number drawn from a raised cosine distribution with parameters mu (mean) and s (scale parameter).

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

If mu or s is NaN or s <= 0, the function returns NaN.

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

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

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

cosine.factory( [mu, s, ][options] )

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

var rand = cosine.factory();

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

If provided mu and s, the returned generator returns random variates from the specified distribution.

var rand = cosine.factory( 10.0, 2.0 );

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

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

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

var rand = cosine.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 = cosine.factory({
    'seed': 12345
});

var r = rand( 1.0, 2.0 );
// returns 2.0585533502230646

rand = cosine.factory( 1.0, 2.0, {
    'seed': 12345
});

r = rand();
// returns 2.0585533502230646

cosine.NAME

The generator name.

var str = cosine.NAME;
// returns 'cosine'

cosine.PRNG

The underlying pseudorandom number generator.

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

cosine.SEED

The value used to seed cosine().

var rand;
var r;
var i;

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

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

Examples

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

var seed;
var rand;
var i;

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

// Create a new pseudorandom number generator...
seed = 1234;
rand = cosine.factory( 5.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 = cosine.factory( 0.0, 1.0, {
    'seed': cosine.SEED
});
console.log( '\nseed: %d', cosine.SEED );
for ( i = 0; i < 100; i++ ) {
    console.log( rand() );
}