All Projects → mafintosh → pick-random-stream

mafintosh / pick-random-stream

Licence: MIT license
Uniformly pick a random value from a stream

Programming Languages

javascript
184084 projects - #8 most used programming language

pick-random-stream

Uniformly pick a random value from a stream

npm install pick-random-stream

build status

Usage

var random = require('pick-random-stream')

someStream.pipe(random()).on('data', function (data) {
  console.log('current random element is', data)
})

The random value will be chosen with propability 1/n where n is the total number of elements in the stream

For example to pick a random node module on npm you can do

var JSONStream = require('JSONStream')
var request = require('request')
var random = require('pick-random-stream')

request('http://node-modules.com/modules.json')
  .pipe(JSONStream.parse('*'))
  .pipe(random())
  .on('data', function (module) {
    console.log('current random module is', module)
  })

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].