Skip to content

Commit

Permalink
Updated docs. Fixed bug in weightedPick
Browse files Browse the repository at this point in the history
  • Loading branch information
jocafa committed Apr 30, 2012
1 parent 22d0365 commit 93088db
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Nonsense.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
};

Nonsense.prototype.weightedPick = function(ary) {
return ary[~~Math.pow(this.frac(), 2) * ary.length];
return ary[~~(Math.pow(this.frac(), 2) * ary.length)];
};

Nonsense.prototype.word = function() {
Expand Down
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,43 @@ Nonsense
Generate repeatable random data in JS

Inspired by [Faker.js](http://github.com/Marak/Faker.js)
Uses slightly modified [Alea PRNG](http://baagoe.org/en/wiki/Alea)


## Usage

### Instantiation
To create a new Nonsense instance, do `var ns = new Nonsense();`. You can pass any number of arbitrary arguments to the `Nonsense()` constructor to be used as seed data. If you don't pass anything, it will just use the default.

### Seeding
If you want to reset the seed of an instance you already have, call `ns.sow()` and pass in the seed data you want to use. The constructor calls `sow()` internally on instantiation.

### Numbers
- `integer()` - returns a random integer between 0 and 2^32
- `frac()` - returns a random real number between 0 and 1
- `real()` - returns a random real number between 0 and 2^32
- `integerInRange(min, max)` - returns a random integer between min and max
- `realInRange(min, max)` - returns a random real number between min and max
- `normal()` - returns a random real number between -1 and 1

### Utilities
- `uuid()` - returns a valid v4 UUID hex string
- `pick(array)` - returns a random member of `array`
- `weightedPick(array)` - returns a random member of `array`, favoring the earlier entries
- `timestamp(min, max)` - returns a random timestamp between min and max, or between the beginning of 2000 and the end of 2020 if min and max aren't specified

### Language
- `word()` - returns a random word of lipsum
- `words(n)` - returns `n` random words of lipsum, 3 if not specified
- `sentence()` - returns a random lipsum sentence
- `sentences(n)` - returns `n` random lipsum sentences, 3 if not specified

### Miscellaneous
- `firstName()` - returns a random common first name
- `lastName()` - returns a random common last name
- `name()` - returns a random first and last name
- `jobTitle()` - returns a random job title
- `buzzPhrase()` - returns a random web 2.0 business plan...

License
-------
Expand Down

0 comments on commit 93088db

Please sign in to comment.