Skip to content

Commit

Permalink
Merge pull request #14 from dtudury/rebase3
Browse files Browse the repository at this point in the history
make set selection evenly distributed
  • Loading branch information
fent committed Sep 19, 2014
2 parents bc48f0a + 0db5c56 commit a85a4ea
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 251 deletions.
30 changes: 13 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ new RandExp(/<([a-z]\w{0,20})>foo<\1>/).gen();

// wildcard
new RandExp(/random stuff: .+/).gen();
// => random stuff: 湐箻ໜ䫴␩⶛㳸長���邓蕲뤀쑡篷皇硬剈궦佔칗븛뀃匫鴔事좍ﯣ⭼ꝏ䭍詳蒂䥂뽭
// => random stuff: l3m;Hf9XYbI [YPaxV>U*4-_F!WXQh9>;rH3i l!8.zoh?[utt1OWFQrE ^~8zEQm]~tK

// ignore case
new RandExp(/xxx xtreme dragon warrior xxx/i).gen();
Expand Down Expand Up @@ -53,24 +53,22 @@ Regular expressions are used in every language, every programmer is familiar wit
Thanks to [String-Random](http://search.cpan.org/~steve/String-Random-0.22/lib/String/Random.pm) for giving me the idea to make this in the first place and [randexp](https://github.com/benburkert/randexp) for the sweet `.gen()` syntax.


# Negated Character Sets
Sets like the `.` character will match anything except a new line. In this case, a character with a random char code between 0 and 65535 will be generated. If you want to overwrite this function you can change the `anyRandChar` function in the randexp object.

# Default Range
The default generated character range includes printable ASCII. In order to add or remove characters,
a `defaultRange` attribute is exposed. you can `subtract(from, to)` and `add(from, to)`
```js
var randexp = new RandExp(/./);
randexp.anyRandChar = function() {
return 'c';
};
var randexp = new RandExp(/random stuff: .+/);
randexp.defaultRange.subtract(32, 126);
randexp.defaultRange.add(0, 65535);
randexp.gen();
// => random stuff: 湐箻ໜ䫴␩⶛㳸長���邓蕲뤀쑡篷皇硬剈궦佔칗븛뀃匫鴔事좍ﯣ⭼ꝏ䭍詳蒂䥂뽭
```

If using `RandExp.sugar()`
# Custom PRNG
The default randomness is provided by `Math.random()`. If you need to use a seedable or cryptographic PRNG you
can override `RandExp.prototype.randInt` or `randexp.randInt` (where `randexp` is an instance of `RandExp`. `randInt(from, to)` accepts an inclusive range and returns a randomly selected
number within that range.

```js
var regexp = /./;
regexp.anyRandChar = function() {
return 'c';
};
```

# Infinite Repetitionals

Expand All @@ -97,8 +95,6 @@ There are some regular expressions which can never match any string.

* Custom negated character sets with two sets inside that cancel each other out. Example: `/[^\w\W]/`. If you give this to randexp, it will ignore both set tokens.

Other cancelling out character sets like `/[^\D]/` are bad too. These are the same as `/[\d]/`. Except it will be slow in generating a matching string because it will first generate a random character and then check if it's in the set inside. It will take a while to randomly generate an integer out of 65535 characters.


# Install
### Node.js
Expand Down
Loading

0 comments on commit a85a4ea

Please sign in to comment.