{"_id":"compute-lcg","_rev":"7-5ed5e0fe6d7854e9aa222c2eb6f463da","name":"compute-lcg","description":"A linear congruential pseudorandom number generator (lcg).","dist-tags":{"latest":"1.0.0"},"versions":{"0.0.0":{"name":"compute-lcg","version":"0.0.0","description":"A linear congruential pseudorandom number generator (lcg).","author":{"name":"rgizz","email":"gztown2216@yahoo.com"},"contributors":[{"name":"rgizz","email":"gztown2216@yahoo.com"}],"scripts":{"test":"mocha","test-cov":"istanbul cover ./node_modules/.bin/_mocha --dir ./reports/coverage -- -R spec","coveralls":"istanbul cover ./node_modules/.bin/_mocha --dir ./reports/coveralls/coverage --report lcovonly -- -R spec && cat ./reports/coveralls/coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./reports/coveralls"},"main":"./lib","repository":{"type":"git","url":"git://github.com/compute-io/lcg.git"},"keywords":["compute.io","compute","computation","mathematics","math","statistics","stats","random","rand","generator","lcg","seed","seedable"],"bugs":{"url":"https://github.com/compute-io/lcg/issues"},"dependencies":{},"devDependencies":{"chai":"1.x.x","coveralls":"^2.11.1","istanbul":"^0.3.0","jshint":"^2.5.10","jshint-stylish":"^1.0.0","mocha":"1.x.x"},"licenses":[{"type":"MIT","url":"http://www.opensource.org/licenses/MIT"}],"gitHead":"30bbf1754056db42b26800a0f48144eb48cf48b2","homepage":"https://github.com/compute-io/lcg","_id":"compute-lcg@0.0.0","_shasum":"bb506ade0d16e31365406b03b83b376e678e9de3","_from":".","_npmVersion":"1.4.28","_npmUser":{"name":"rgizz","email":"gztown2216@yahoo.com"},"maintainers":[{"name":"rgizz","email":"gztown2216@yahoo.com"}],"dist":{"shasum":"bb506ade0d16e31365406b03b83b376e678e9de3","tarball":"https://registry.npmjs.org/compute-lcg/-/compute-lcg-0.0.0.tgz","integrity":"sha512-WMd7Bvdz+Ee9EpFw+t5QjLLfwkntMfY7c1HEObw6ZzeMsZmxA8TjQstjvdpmi799eA+XO15Iz3102RUOrNlBIw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCZ27WvRluw2ci1qTeKEkJRaqBvyTSdRJC18WYMDznMVAIgW5bJSJPxyAYAlpBHBDHkIqgbFlpFNIB75eJavMHwRsY="}]}},"1.0.0":{"name":"compute-lcg","version":"1.0.0","description":"A linear congruential pseudorandom number generator (lcg).","author":{"name":"rgizz","email":"gztown2216@yahoo.com"},"contributors":[{"name":"rgizz","email":"gztown2216@yahoo.com"}],"scripts":{"test":"mocha","test-cov":"istanbul cover ./node_modules/.bin/_mocha --dir ./reports/coverage -- -R spec","coveralls":"istanbul cover ./node_modules/.bin/_mocha --dir ./reports/coveralls/coverage --report lcovonly -- -R spec && cat ./reports/coveralls/coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./reports/coveralls"},"main":"./lib","repository":{"type":"git","url":"git://github.com/compute-io/lcg.git"},"keywords":["compute.io","compute","computation","mathematics","math","statistics","stats","random","rand","generator","lcg","seed","seedable"],"bugs":{"url":"https://github.com/compute-io/lcg/issues"},"dependencies":{},"devDependencies":{"chai":"1.x.x","coveralls":"^2.11.1","istanbul":"^0.3.0","jshint":"^2.5.10","jshint-stylish":"^1.0.0","mocha":"1.x.x"},"licenses":[{"type":"MIT","url":"http://www.opensource.org/licenses/MIT"}],"gitHead":"fcf400b105bab406ed2ac82f5bd356a1c13c3ac6","homepage":"https://github.com/compute-io/lcg","_id":"compute-lcg@1.0.0","_shasum":"f0371e9325484f337349a12a4d715539899daf72","_from":".","_npmVersion":"1.4.28","_npmUser":{"name":"rgizz","email":"gztown2216@yahoo.com"},"maintainers":[{"name":"rgizz","email":"gztown2216@yahoo.com"}],"dist":{"shasum":"f0371e9325484f337349a12a4d715539899daf72","tarball":"https://registry.npmjs.org/compute-lcg/-/compute-lcg-1.0.0.tgz","integrity":"sha512-oTt5yO5saNm2ysCKtjUjefwEzeQl3ClAktIq3Or8t2kw5q+zaygQuAy1qP0I0qRnjY7le38sryqf/92Fk0+dPQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC15JRWWNoaGMDPl0kZupH+2xtn3Bd1zh8/MZS9oCO6BwIgfAxWpgJrEJbX6lPWILznQqZ7Wj3Stm5k/UzS9HlCs/U="}]}}},"readme":"Linear Congruential Generator\n===\n[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Dependencies][dependencies-image]][dependencies-url]\n\n> A linear congruential pseudorandom number generator (lcg). \n\n\n## Installation\n\n``` bash\n$ npm install compute-lcg\n```\nFor use in the browser, use [browserify](https://github.com/substack/node-browserify).\n\n## Usage\n\nTo use the module,\n\n``` javascript\nvar lcg = require( 'compute-lcg' );\n```\n\n\n#### lcg( [seed] )\n\nReturns a pseudorandom number generator.\n\n``` javascript\nvar rand = lcg();\n```\n\nTo seed the generator, provide a positive `integer` seed\n\n``` javascript\nvar rand = lcg( 1234 );\n```\n\n#### rand( [n] )\n\nReturns a pseudorandom floating-point `number` between `0` and `1`.\n\n``` javascript\nvar val = rand();\n```\n\nIf provided a length `n`, the method returns an `array` of pseudorandom numbers.\n\n``` javascript\nvar arr = rand( 10 );\n// returns [...]\n```\n\n\n## Notes\n\nFor a general lcg reference, see [Wikipedia](#ref-wikipedia). Linear congruential generators use the following recurrence relation:\n\n<pre>\nX_{n+1} = ( a*X_n + c ) mod m\n</pre>\n\nIn this implementation, the constants `a`, `c`, and `m` have the following values: \n\n<pre>\na = 16807\nc = 0\nm = 2^31 - 1 => 2147483647\n</pre>\n\nThe values for `a`, `c`, and `m` are taken from Park and Miller, [\"Random Number Generators: Good Ones Are Hard To Find\"](#ref-park-miller). Park's and Miller's article is also the basis for a recipe in the second edition of [_Numerical Recipes in C_](#ref-numerical-recipes-1). For the most part, this implementation follows [_Numerical Recipes_](#ref-numerical-recipes-1).  \n\n\n### Period\n\nThe generator has a period of approximately 2.1e9 [[4]](#ref-numerical-recipes-2). \n\n### When To Use\n\nLcg is fast and uses little memory.  On the other hand, because the generator is a simple linear congruential generator, it has recognized shortcomings. By today's PRNG standards, its period, on the order of 2e9, is relatively short.  More importantly, the \"randomness quality\" of its output is not of the best quality.  These defects rule it out, for example, in Monte Carlo simulations and in cryptographic applications.  For more on the advantages and disadvantages of LCGs see [[5]](#ref-wikipedia-2).\n\n\n\n## Examples\n\n``` javascript\nvar lcg = require( 'compute-lcg' );\n\n// Create a new (unseeded) generator:\nvar rand = lcg();\n\n// Generate some pseudorandom numbers...\nfor ( var i = 0; i < 10; i++ ) {\n\tconsole.log( rand() );\n}\n\n// Create a new (seeded) generator:\nrand = lcg( 1 );\nfor ( var j = 0; j < 10; j++ ) {\n\tconsole.log( rand() );\n}\n\n// Create a new generator seeded with the same seed as the previous generator:\nrand = lcg( 1 );\nconsole.log( rand( 10 ).join( '\\n' ) );\n```\n\nTo run the example code from the top-level application directory,\n\n``` bash\n$ node ./examples/index.js\n```\n\n\n## Tests\n\n### Unit\n\nUnit tests use the [Mocha](http://mochajs.org/) test framework with [Chai](http://chaijs.com) assertions. To run the tests, execute the following command in the top-level application directory:\n\n``` bash\n$ make test\n```\n\nAll new feature development should have corresponding unit tests to validate correct functionality.\n\n\n### Test Coverage\n\nThis repository uses [Istanbul](https://github.com/gotwarlost/istanbul) as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:\n\n``` bash\n$ make test-cov\n```\n\nIstanbul creates a `./reports/coverage` directory. To access an HTML version of the report,\n\n``` bash\n$ make view-cov\n```\n\n#### Test Notes\n\nTest data generated from the C code published in [_Numerical Recipes_](#ref-numerical-recipes-1).\n\n\n## References\n\n<a name=\"ref-wikipedia-1\"></a>\n1. Wikipedia. [Linear Congruential Generator](https://en.wikipedia.org/wiki/Linear_ congruential_ generator)\n\n<a name=\"ref-park-miller\"></a>\n2. S.K. Park and K.W. Miller (1988). \"Random Number Generators: Good Ones Are Hard To Find\". Communications of the ACM 31 (10): 1192-1201.\n\n<a name=\"ref-numerical-recipes-1\"></a>\n3. William H. Press, et. al., _Numerical Recipes in C: The Art of Scientific Computing_, Section 7.1 \"Uniform Deviates\" (2d ed. 1992) (hereinafter _Numerical Recipes_).  \n\n<a name=\"ref-numerical-recipes-2\"></a>\n4. _Numerical Recipes_, p. 279.\n\n<a name=\"ref-wikipedia-2\"></a>\n5. Wikipedia. [Linear Congruential Generator](http://en.wikipedia.org/wiki/Linear_congruential_generator#Advantages_and_disadvantages_of_LCGs).\n\n\n---\n## License\n\n[MIT license](http://opensource.org/licenses/MIT). \n\n\n## Copyright\n\nCopyright &copy; 2014. rgizz.\n\n\n[npm-image]: http://img.shields.io/npm/v/compute-lcg.svg\n[npm-url]: https://npmjs.org/package/compute-lcg\n\n[travis-image]: http://img.shields.io/travis/compute-io/lcg/master.svg\n[travis-url]: https://travis-ci.org/compute-io/lcg\n\n[coveralls-image]: https://img.shields.io/coveralls/compute-io/lcg/master.svg\n[coveralls-url]: https://coveralls.io/r/compute-io/lcg?branch=master\n\n[dependencies-image]: http://img.shields.io/david/compute-io/lcg.svg\n[dependencies-url]: https://david-dm.org/compute-io/lcg\n\n[dev-dependencies-image]: http://img.shields.io/david/dev/compute-io/lcg.svg\n[dev-dependencies-url]: https://david-dm.org/dev/compute-io/lcg\n\n[github-issues-image]: http://img.shields.io/github/issues/compute-io/lcg.svg\n[github-issues-url]: https://github.com/compute-io/lcg/issues\n","maintainers":[{"name":"rgizz","email":"gztown2216@yahoo.com"}],"time":{"modified":"2022-06-13T20:29:47.725Z","created":"2015-01-15T17:03:59.719Z","0.0.0":"2015-01-15T17:03:59.719Z","1.0.0":"2015-01-15T17:29:21.510Z"},"homepage":"https://github.com/compute-io/lcg","keywords":["compute.io","compute","computation","mathematics","math","statistics","stats","random","rand","generator","lcg","seed","seedable"],"repository":{"type":"git","url":"git://github.com/compute-io/lcg.git"},"contributors":[{"name":"rgizz","email":"gztown2216@yahoo.com"}],"author":{"name":"rgizz","email":"gztown2216@yahoo.com"},"bugs":{"url":"https://github.com/compute-io/lcg/issues"},"readmeFilename":"README.md","users":{"liviud":true}}