Skip to content

Commit 9a1e46b

Browse files
committed
v0.2
1 parent ae434cc commit 9a1e46b

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,31 @@
1414

1515
Also, besides their normal use, I have added functions to go backward. The **Mersenne Twister**
1616
and **LCG**'s are reversible.
17-
I got the idea of reversing the MT from here: [Cracking Random Number Generators - Part 3](https://jazzy.id.au/2010/09/22/cracking_random_number_generators_part_3.html).
1817
Also, **LCG**'s and **subtractive generators** are trivial to revert.
1918

19+
I got the idea of reversing the generators from several places, after I had to break the seed of some generator, in order to reduce the size of the archived dataset.
20+
21+
## Disclaimer
22+
*There are some cases in which the reverse does not work as expected. Try not to mix next and prev versions of the methods as you might run into strange situations.*
23+
*Some of the situations are captured by unit tests which are currently marked as ignored.*
24+
*Most of the time things go well.*
25+
26+
***Nevertheless, use it at your own risk. This library comes with no guarantees.***
27+
28+
## Usage
29+
#### Maven dependency
30+
```xml
31+
<dependency>
32+
<groupId>ro.derbederos</groupId>
33+
<artifactId>untwist</artifactId>
34+
<version>0.2</version>
35+
</dependency>
36+
```
37+
#### Gradle dependency
38+
```groovy
39+
compile 'ro.derbederos:untwist:0.2'
40+
```
41+
2042
Enjoy using them!
2143

2244
[build-status-svg]: https://travis-ci.org/csoroiu/untwist.svg?branch=master

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
<groupId>ro.derbederos</groupId>
2424
<artifactId>untwist</artifactId>
25-
<version>0.2-SNAPSHOT</version>
25+
<version>0.2</version>
2626

2727
<name>untwist</name>
2828
<description>Java 8+ collection of PRNG's from CLR (.NET), FreePascal, TurboPascal, Python.</description>

src/main/java/ro/derbederos/untwist/CLRRandom.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ private void initialize(int seed) {
158158

159159
/**
160160
* The reverse of {@link #sample()}.
161+
* <p>
161162
* Returns a random floating-point number between {@code 0.0} and {@code 1.0}.
162163
*
163164
* @return A double-precision floating point number that is greater than or equal to {@code 0.0},
@@ -323,6 +324,7 @@ public int nextInt() {
323324

324325
/**
325326
* The reverse of {@link #nextInt()}.
327+
* <p>
326328
* Returns a non-negative random integer.
327329
* <p>
328330
* <font color="red">This violates the contract of {@link ReverseRandomGenerator#prevInt()}</font>
@@ -363,6 +365,7 @@ public int nextInt(int minValue, int maxValue) {
363365

364366
/**
365367
* The reverse of {@link #nextInt(int, int)}.
368+
* <p>
366369
* Returns a random integer that is within a specified range.
367370
*
368371
* @param minValue the inclusive lower bound of the random number returned.
@@ -405,6 +408,7 @@ public int nextInt(int maxValue) {
405408

406409
/**
407410
* The reverse of {@link #nextInt(int)}.
411+
* <p>
408412
* Returns a non-negative random integer that is less than the specified maximum.
409413
*
410414
* @param maxValue the exclusive upper bound of the random number to be generated. {@code maxValue} must
@@ -435,6 +439,7 @@ public double nextDouble() {
435439

436440
/**
437441
* The reverse of {@link #nextDouble()}.
442+
* <p>
438443
* Returns a random floating-point number that is greater than or equal to {@code 0.0},
439444
* and less than {@code 1.0}.
440445
*
@@ -484,6 +489,7 @@ public void nextBytes(byte[] buffer) {
484489

485490
/**
486491
* The reverse of {@link #nextBytes(byte[])}.
492+
* <p>
487493
* Fills the elements of a specified array of bytes with random numbers.
488494
*
489495
* @param buffer an array of bytes to contain random numbers.
@@ -515,6 +521,7 @@ public long nextLong() {
515521

516522
/**
517523
* The reverse of {@link #nextLong()}.
524+
* <p>
518525
* Returns a 64 bit random integer (long). Unlike {@link #prevInt()}, all 2<sup>64</sup> possible
519526
* {@code long} values should be produced with (approximately) equal probability.
520527
*
@@ -541,6 +548,7 @@ public boolean nextBoolean() {
541548

542549
/**
543550
* The reverse of {@link #nextBoolean()}.
551+
* <p>
544552
* Returns a random boolean.
545553
* Uses the formula {@code nextInt(2) == 1}.
546554
*

src/main/java/ro/derbederos/untwist/ReverseBitsStreamGenerator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public abstract class ReverseBitsStreamGenerator extends BitsStreamGenerator imp
3333

3434
/**
3535
* The reverse of {@link #next(int)}.
36+
* <p>
3637
* Generate previous pseudorandom number.
3738
* <p>
3839
* This method is the core generation algorithm.

0 commit comments

Comments
 (0)