fj.Rng Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of functionaljava Show documentation
Show all versions of functionaljava Show documentation
Functional Java is an open source library that supports closures for the Java programming language
package fj;
/**
* Created by MarkPerry on 7/07/2014.
*/
public abstract class Rng {
public abstract P2 nextInt();
public abstract P2 nextLong();
// [low, high] inclusive
public final P2 range(int low, int high) {
return nextNatural().map2(x -> (x % (high - low + 1)) + low);
}
public final P2 nextNatural() {
return nextInt().map2(x -> x < 0 ? -(x + 1) : x);
}
}