Create a stream of random values from dictionary
@author Arne Schubert <atd.schubert@gmail.com>
@constructor
@memberOf streamLib
@augments {stream.Readable}
777011
function Random(opts) {
    Readable.apply(this, arguments);

    if (opts && opts.objectMode) {
        this.objectMode = true;
    }

    this.dictionary = ['1', '0'];
}
998755
public static function create(PdfDictionary $dictionary, $stream)
    {
        $v = new self;
        $v->value = $dictionary;
        $v->stream = (string) $stream;

        return $v;
    }
538491
function create(list) {
  let dist = l.reduce(list, function(acc, el, i) {
    for(let j = 0; j < el.weight * 100; j++) {
      acc.push(i);
    }
    return acc;
  }, []);

  return function() {
    let i = dist[l.random(0, dist.length - 1)];
    return [i, list[i]];
  };
}
607947
function proxy (stream, key) {
  if (key in stream) {
    debug('not proxying prop "%s" because it already exists on target stream', key);
    return;
  }

  function get () {
    return stream.res[key];
  }
  function set (v) {
    return stream.res[key] = v;
  }
  Object.defineProperty(stream, key, {
    configurable: true,
    enumerable: true,
    get: get,
    set: set
  });
}
1294873
function random(array, len) {
  const size = array.length;
  const randomIndexes = crypto.randomBytes(len).toJSON().data;
  return randomIndexes.map((char) => array[char % size]).join('');
}
647756
function recreate(makeStream, options) {
  if (options === undefined && isObject(makeStream)) {
    options = makeStream;
    makeStream = options.makeStream;
  }

  options = options || {};

  if (options.connect === undefined) {
    options.connect = true;
  }

  var connectedEvent = options.connectedEvent || 'open';

  var stream = through();
  stream.inverse = through();

  stream.inverse.pause();

  stream.write = function(chunk) {
    return stream.inverse.write(chunk);
  };

  stream.connect = function() {
    stream.underlying = makeStream();

    stream.inverse.pipe(stream.underlying, {end: false});

    stream.underlying.on('data', function(chunk) {
      return stream.emit('data', chunk);
    });

    stream.underlying.on(connectedEvent, function() {
      stream.backoff.reset();
      stream.inverse.resume();
      stream.emit('open');
      stream.emit('underlying-open');
    });

    stream.underlying.on('end', function() {
      stream.inverse.pause();
      if (!stream.preventBackoff) {
        stream.backoff.backoff();
      }
      stream.emit('underlying-end');
    });

    stream.underlying.on('error', function(e) {
      stream.inverse.pause();
      if (!stream.preventBackoff) {
        stream.backoff.backoff();
      }
      stream.emit('underlying-error');
    });
  };

  var origEnd = stream.end.bind(stream);

  stream.end = function() {
    stream.preventBackoff = true;
    stream.underlying.end();
    return origEnd();
  };

  stream.backoff = options.backoff || backoff.exponential(options);

  stream.backoff.on('backoff', function(num, delay) {
    stream.emit('backoff-schedule', num, delay);
  });

  stream.backoff.on('ready', function() {
    stream.connect();
    stream.emit('backoff-ready');
  });

  stream.backoff.on('fail', function() {
    stream.emit('backoff-fail');
  });


  if (options.connect) {
    stream.connect();
  }

  return stream;
}
1028661
function(options) {
  "use strict";
  stream.Transform.call(this, options);

  options = options || {};

  this.probability = options.probability || 0;
  this.deviation = Math.abs(options.deviation || 0);

  this.whiteList = options.whiteList || [];
  this.blackList = options.blackList || [];
  this.func = options.func;
}
1150939
public static void foreachRandomInt(int streamSize, int exclusiveBound,
            IntConsumer eachRandomIntConsumer) {
        foreachRandomInt(streamSize, new Random(), exclusiveBound,
                eachRandomIntConsumer);
    }
926040
function BufferStreamReader (data, options) {
  if (!(this instanceof BufferStreamReader)) {
    return new BufferStreamReader(data);
  }

  if (!options) {
    options = {};
  }

  stream.Readable.call(this, options);

  this._data = null;
  this._chunkSize = options.chunkSize || -1;

  if (typeof data === 'string') {
    this._data = new Buffer(data, options.encoding || 'utf8');
  } else if (Buffer.isBuffer(data)) {
    this._data = data;
  }
}
920777
function StreamCopier() {
	var self = this
	stream.Stream.call(this)
	this.writable = true
	this.log = log
	this.write = write
	this.setPrepend = setPrepend
	this.pLog = pLog
	this.addStream = addStream
	this.removeStream = removeStream
	this.end = end
	this.destroy = destroy
	var prepend
	var streamIndex = 0
	var streams = {}

	function pLog() {
		commonLog(Array.prototype.slice.call(arguments), prepend)
	}

	function log() {
		commonLog(Array.prototype.slice.call(arguments))
	}

	function commonLog(args, prepend) {
		var s = util.format.apply(this, args) + '\n'
		if (prepend) s = prepend + ' ' + s
		write(s)
	}

	function setPrepend(s) {
		prepend = s ? String(s) : ''
		return self
	}

	function addStream(stream, name) {
		if (self.writable) {
			var i = streamIndex++
			streams[i] = {
				stream: stream,
				name: name
			}
		} else self.emit('error', 'Stream not writable')
		return i
	}

	function removeStream(no) {
		delete streams[no]
	}

	function write(s) {
		var err
		var didCb
		var args = Array.prototype.slice.call(arguments)
		var cb = typeof args[args.length - 1] === 'function' ? args.pop() : null

		var cbCounter = Object.keys(streams).length + 1
		for (var streamNo in streams) doWrite(streamNo)
		end()

		function doWrite(streamNo) {
			var stream = streams[streamNo].stream
			if (stream.writable) stream.write.apply(stream, args.concat(writeResult))
			else streamLost()

			function writeResult(e) {
				if (!e) end()
				else streamLost(e) // a write resulted in error
			}

			function streamLost(e) {
				var isError = Object.keys(streams).length == 1 // if we lost the last stream, it's error

				// emit the event
				eventType = isError ? 'error' : 'warning'
				var msg = 'Stream ' + streams[streamNo].name + ' no longer writable'
				if (e) msg += ': ' + err.msg
				self.emit(eventType, msg)
				delete streams[streamNo]

				if (isError) {
					if (!e) e = new Error(msg)
					self.writable = false
					end(e)
				} else write(msg, end) // write to remaining streams
			}
		}

		function end(e) {
			if (!err && e) err = e
			if (!err) {
				if (!--cbCounter && cb) {
					cb()
				}
			} else if (!didCb && cb) {
				didCb = true
				cb(err)
			}
		}
	}

	function end(s) {
		var err
		var args = Array.prototype.slice.call(arguments)
		var cb = typeof args[args.length - 1] === 'function' ? args.pop() : null
		var cbCounter = Object.keys(streams).length + 1

		if (args.length) write.apply(this, args.concat(allWritten))
		else allWritten()

		function allWritten(e) {
			if (e && !err) err = e
			for (var streamNo in streams) doEnd(streamNo)
			end()
		}

		function doEnd(streamNo) {
			streams[streamNo].stream.end(endResult)

			function endResult(e) {
				if (e) {
					if (!err) err = e
					self.emit('error', 'Stream ' + streams[streamNo].name + ' end error: ' + e.message)
				}
				delete streams[streamNo]
				end()
			}
		}

		function end() {
			if (!--cbCounter) {
				self.writable = false
				if (cb)
					if (err) cb(err)
					else cb()
			}
		}
	}

	function destroy(cb) {
		var cbCounter = Object.keys(streams).length + 1
		for (var streamNo in streams) doDestroy(streamNo)
		end()

		function doDestroy(streamNo) {
			streams[streamNo].stream.destroy(endResult)

			function destroyResult(e) {
				if (e) {
					if (!err) err = e
					self.emit('error', 'Stream ' + streams[streamNo].name + ' destroy error: ' + e.message)
				}
				delete streams[streamNo]
				end()
			}
		}

		function end() {
			if (!--cbCounter) {
				self.writable = false
				if (cb)
					if (err) cb(err)
					else cb()
			}
		}
	}
}
67209
def stream(stream_id, update_max_id = true)
      raise ArgumentError, "stream_id can't be 0" if stream_id == 0

      stream = @streams[stream_id]
      if stream
        if stream.state == :idle && stream_id < @max_stream_ids[stream_id % 2]
          stream.set_state(:closed_implicitly)
        end
      elsif stream_id > @max_stream_ids[stream_id % 2]
        @max_stream_ids[stream_id % 2] = stream_id if update_max_id
        stream = Stream.new(self, stream_id, state: :idle)
        callback(:stream, stream)
        @streams[stream_id] = stream
      else
        stream = Stream.new(self, stream_id, state: :closed_implicitly)
        callback(:stream, stream)
      end

      stream
    end
453262
public static IntStream buildRandomIntStream(int streamSize, Random random,
            int exclusiveBound) {
        return buildRandomIntStream(streamSize,
                () -> random.nextInt(exclusiveBound));
    }
193406
function concatStreams(array) {
  var concat = new stream.PassThrough();

  function pipe(i) {
    if (i < array.length - 1) {
      array[i].pipe(concat, {end: false});
      array[i].on('end', function () { pipe(i + 1) });
    } else {
      array[i].pipe(concat);
    }
  }
  if (array.length > 0) {
    pipe(0);
  }

  return concat;
}
921494
function create(targetScrollY) {
  var scrollPositionStream = ScrollStream.create();
  var overTheLineStream = Stream.create();
  var pastScrollY = false;
  var firstRun = true;

  Stream.onValue(scrollPositionStream, function onScrollTrackPosition_(currentScrollY) {
    if ((firstRun || pastScrollY) && (currentScrollY < targetScrollY)) {
      pastScrollY = false;
      Stream.emit(overTheLineStream, ['before', targetScrollY]);
    } else if ((firstRun || !pastScrollY) && (currentScrollY >= targetScrollY)) {
      pastScrollY = true;
      Stream.emit(overTheLineStream, ['after', targetScrollY]);
    }

    firstRun = false;
  });

  return overTheLineStream;
}
367177
function create(key, value) {
  if (!Buffer.isBuffer(key)) {
    throw new TypeError('expected buffer')
  }

  return {
    key,
    value,
    left: null,
    right: null,
    height: 0
  }
}
227439
function streamFactory( options ) {
		if ( !arguments.length ) {
			options = {};
		}
		options = copyOptions( options );
		/**
		* FUNCTION: createStream( arr )
		*	Creates a stream.
		*
		* @param {Array} arr - array to convert into a readable stream
		* @returns {Stream} Readable stream
		*/
		return function createStream( arr ) {
			return new Stream( arr, options );
		};
	}
427439
async function create(channelName, options = {}) {
    options = fillOptionsWithDefaults(options);
    const time = microSeconds();
    const paths = getPaths(channelName);
    const ensureFolderExistsPromise = ensureFoldersExist(channelName, paths);
    const uuid = randomToken(10);

    const state = {
        time,
        channelName,
        options,
        uuid,
        paths,
        // contains all messages that have been emitted before
        emittedMessagesIds: new ObliviousSet(options.node.ttl * 2),
        messagesCallbackTime: null,
        messagesCallback: null,
        // ensures we do not read messages in parrallel
        writeBlockPromise: Promise.resolve(),
        otherReaderClients: {},
        // ensure if process crashes, everything is cleaned up
        removeUnload: unload.add(() => close(state)),
        closed: false
    };

    if (!OTHER_INSTANCES[channelName]) OTHER_INSTANCES[channelName] = [];
    OTHER_INSTANCES[channelName].push(state);

    await ensureFolderExistsPromise;
    const [
        socketEE,
        infoFilePath
    ] = await Promise.all([
        createSocketEventEmitter(channelName, uuid, paths),
        createSocketInfoFile(channelName, uuid, paths),
        refreshReaderClients(state)
    ]);
    state.socketEE = socketEE;
    state.infoFilePath = infoFilePath;

    // when new message comes in, we read it and emit it
    socketEE.emitter.on('data', data => {

        // if the socket is used fast, it may appear that multiple messages are flushed at once
        // so we have to split them before
        const singleOnes = data.split('|');
        singleOnes
            .filter(single => single !== '')
            .forEach(single => {
                try {
                    const obj = JSON.parse(single);
                    handleMessagePing(state, obj);
                } catch (err) {
                    throw new Error('could not parse data: ' + single);
                }
            });
    });

    return state;
}