time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

factory.js (3114B)


      1 /**
      2 * @license Apache-2.0
      3 *
      4 * Copyright (c) 2018 The Stdlib Authors.
      5 *
      6 * Licensed under the Apache License, Version 2.0 (the "License");
      7 * you may not use this file except in compliance with the License.
      8 * You may obtain a copy of the License at
      9 *
     10 *    http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing, software
     13 * distributed under the License is distributed on an "AS IS" BASIS,
     14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15 * See the License for the specific language governing permissions and
     16 * limitations under the License.
     17 */
     18 
     19 'use strict';
     20 
     21 // MODULES //
     22 
     23 var copy = require( '@stdlib/utils/copy' );
     24 var RandomStream = require( './main.js' );
     25 
     26 
     27 // MAIN //
     28 
     29 /**
     30 * Returns a function for creating readable streams which generate pseudorandom numbers drawn from a standard normal distribution.
     31 *
     32 * @param {Options} [options] - stream options
     33 * @param {boolean} [options.objectMode=false] - specifies whether a stream should operate in object mode
     34 * @param {(string|null)} [options.encoding=null] - specifies how `Buffer` objects should be decoded to `strings`
     35 * @param {NonNegativeNumber} [options.highWaterMark] - specifies the maximum number of bytes to store in an internal buffer before ceasing to generate additional pseudorandom numbers
     36 * @param {string} [options.sep='\n'] - separator used to join streamed data
     37 * @param {NonNegativeInteger} [options.iter] - number of iterations
     38 * @param {string} [options.name='improved-ziggurat'] - name of a supported pseudorandom number generator (PRNG), which will serve as the underlying source of pseudorandom numbers
     39 * @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers
     40 * @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed
     41 * @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state
     42 * @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state
     43 * @param {PositiveInteger} [options.siter] - number of iterations after which to emit the PRNG state
     44 * @returns {Function} stream factory
     45 *
     46 * @example
     47 * var opts = {
     48 *     'sep': ',',
     49 *     'objectMode': false,
     50 *     'encoding': 'utf8',
     51 *     'highWaterMark': 64
     52 * };
     53 *
     54 * var createStream = factory( opts );
     55 *
     56 * // Create 10 identically configured streams...
     57 * var streams = [];
     58 * var i;
     59 * for ( i = 0; i < 10; i++ ) {
     60 *     streams.push( createStream() );
     61 * }
     62 */
     63 function factory( options ) {
     64 	var opts;
     65 	if ( arguments.length > 0 ) {
     66 		opts = copy( options, 1 );
     67 	} else {
     68 		opts = {};
     69 	}
     70 	return createStream;
     71 
     72 	/**
     73 	* Returns a readable stream for generating pseudorandom numbers drawn from a standard normal distribution.
     74 	*
     75 	* @private
     76 	* @throws {TypeError} options argument must be an object
     77 	* @throws {TypeError} must provide valid options
     78 	* @throws {Error} must provide a valid state
     79 	* @returns {RandomStream} Stream instance
     80 	*/
     81 	function createStream() {
     82 		return new RandomStream( opts );
     83 	}
     84 }
     85 
     86 
     87 // EXPORTS //
     88 
     89 module.exports = factory;