Skip to content

NodeJS support #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# isaac.js
# isaac.js - NodeJS compatibility version
*isaac.js* is a JavaScript implementation of the [ISAAC](http://www.burtleburtle.net/bob/rand/isaac.html) random number generator.

ISAAC is a [CSPRNG](http://en.wikipedia.org/wiki/CSPRNG) designed by [Robert J. Jenkins Jr.](http://burtleburtle.net/bob/) in 1996 and based on RC4. It is designed to be fast and secure.

*isaac.js* is fully compatible with the other *32-bit integer arithmetic* implementations of ISAAC and can be used as a good alternative to the default javascript `Math.random()` function.

##Use
Include isaac.js into your html file: `<script src="isaac.js"></script>`. Then just call `isaac.random()` to get a random real number between 0.0 and 1.0 :
`
npm install isaac
`

`var random_number = isaac.random();`
`var isaac = require( 'isaac' );`

Then just call `isaac.random()` to get a random real number between 0.0 and 1.0 :
`var random_number = isaac.random( );`

If you want a little more control over the PRNG you can reset isaac (all internals to zero) using `isaac.reset()` or use a new seed using `isaac.seed(s)` (*s* can be a string, a number or an array of number). You can also run the PRNG an arbitrary number of time before querying a new random output using `isaac.prng(n)`, where *n* (optional) is the number of run. `isaac.rand()` allow you to get a random 32-bit integer between -2147483648 (0x00000000) and 2147483647 (0xFFFFFFFF).

Expand Down
136 changes: 0 additions & 136 deletions isaac-test.htm

This file was deleted.

10 changes: 6 additions & 4 deletions isaac.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,19 @@ var isaac = (function(){
return {a: acc, b: brs, c: cnt, m: m, r: r};
}

function random(){
return 0.5 + this.rand() * 2.3283064365386963e-10; // 2^-32
}

/* return class object */
return {
'reset': reset,
'seed': seed,
'prng': prng,
'rand': rand,
'random': random,
'internals': internals
};
})(); /* declare and execute */

/* public: output*/
isaac.random = function() {
return 0.5 + this.rand() * 2.3283064365386963e-10; // 2^-32
}
( "undefined" !== ( typeof( module ) ) ) && module.exports && ( module.exports = isaac );
20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"author": "Yves-Marie K. Rinquin",
"name": "isaac",
"description": "ISAAC is a CSPRNG designed by Robert J. Jenkins Jr. in 1996 and based on RC4. It is designed to be fast and secure.",
"version": "0.0.5",
"repository":
{
"type": "git",
"url": "git://github.com/StefanoBalocco/isaac.js.git"
},
"keywords":
[
"prng",
"cprng",
"csprng",
"isaac"
],
"main": "./isaac.js",
"license": "MIT"
}