Skip to content

Commit b1c7d9b

Browse files
committed
Improved README
1 parent 051677e commit b1c7d9b

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

README.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# 1. About rng
2-
rng is an implementation of several well-known pseudo-random number generators which have far better characteristics than Java's built-in generator.
2+
rng is an implementation of several well-known pseudo-random number generators which have far better characteristics than Java's built-in generator. rng can be used for simulations, games (dice rolling, shuffling of playing cards etc.) or for any other application where security is not paramount. Specifically, it should **never** be used for cryptographically secure applications.
33
# 2. Features
44
Within rng you'll find the following generators (in alphabetical order):
55
* [Complementary multiply with carry (CMWC)][gen-cmwc]
@@ -29,8 +29,9 @@ $ mvn clean package -Prng
2929
$ ls -alF target | grep rng
3030
```
3131
# 4. Usage examples
32-
Using any of the generators is super easy. You just need to create an object and then request random number in the range you need.
32+
Using any of the generators is super easy. You just need to create a generator object and then request a random number in the range you need.
3333
## 4.1 Instantiating a generator
34+
Before obtaining pseudo-random numbers, you have to create a generator object:
3435
```java
3536
PRNG.Smart generator = new MersenneTwister.Smart(new MersenneTwister());
3637
```
@@ -39,11 +40,12 @@ In a similar way you would instantiate an object for some other generator, e.g.
3940
PRNG.Smart generator = new XorshiftPlus.Smart(new XorshiftPlus());
4041
```
4142
## 4.2 Generating an integer in given range
43+
This is probably the most common operation with the generator. To generate an integer you always have to specify a _range_ (i.e. lower and upper bound of a number):
4244
```java
43-
IntRange range = new IntRange(1, 6);
44-
int roll = generator.nextInt(range);
45+
IntRange sixSidedDie = new IntRange(1, 6);
46+
int dots = generator.nextInt(sixSidedDie);
4547
```
46-
```IntRange``` class is constant (immutable) so you can share it's instances freely.
48+
This may look a bit verbose, but actually makes your code's intention very explicit. ```IntRange``` class is constant (immutable) so you can share its instances freely.
4749
## 4.3 Generating a double in range [0,1)
4850
```java
4951
double number = generator.nextDouble();
@@ -56,13 +58,18 @@ byte colorIndex = generator.nextByte();
5658
short tetrisScore = generator.nextShort();
5759
char letter = generator.nextChar();
5860
```
59-
6061
# 5. How to contribute
61-
If you spot an error or you think you can add some feature to rng just fork the project and make a pull request.
62+
Additional generators can be easily added. There is only one requirement: every generator must implement the ```PRNG``` interface. This interface has only one method ```int nextInt();``` which must return integer in the whole range, i.e. ```[Integer.MIN_VALUE, Integer.MAX_VALUE]```. And that's it! All the heavy lifting afterwards is done automatically by the ```PRNG.Smart``` class. If you know how to implement some other generator or believe there's a bug somewhere, please fork the project, change/add what you want and make a pull request.
6263
# 6. License
6364
rng is licensed under [GPLv3][gpl] license.
6465
# 7. Credits for previous work
65-
TBD
66+
I would like to say a big thank you to the following people - authors of generators implemented in rng project:
67+
* [Complementary multiply with carry (CMWC)][gen-cmwc] George Marsaglia
68+
* [Mersenne Twister 19937][gen-mt] Makoto Matsumoto and Takuji Nishimura
69+
* [R250][gen-gfsr] Scott Kirkpatrick and Erich Stoll
70+
* [R250/521][gen-gfsr] Scott Kirkpatrick and Erich Stoll
71+
* [Xorshift Plus][gen-xorshiftplus] George Marsaglia
72+
6673
# 8. How to contact author
6774
If you have a question or issue with rng itself please use [Issues][rngissues] link. If you want to talk about anything else, I'm [@\_The\_Java\_Guy\_][twitterhandle] on Twitter.
6875

0 commit comments

Comments
 (0)