@@ -124,38 +124,15 @@ public Random f(final Long x) {
124124 /**
125125 * A standard random generator that uses {@link Random}.
126126 */
127- public static final Rand standard = new Rand (new F <Option <Long >, F <Integer , F <Integer , Integer >>>() {
128- public F <Integer , F <Integer , Integer >> f (final Option <Long > seed ) {
129- return new F <Integer , F <Integer , Integer >>() {
130- public F <Integer , Integer > f (final Integer from ) {
131- return new F <Integer , Integer >() {
132- public Integer f (final Integer to ) {
133- if (from == to ){
134- return from ;
135- }else {
136- final int f = min (from , to );
137- final int t = max (from , to );
138- final int x = Math .abs (t - f );
139- return f + seed .map (fr ).orSome (new Random ()).nextInt (x == Integer .MIN_VALUE ? Integer .MAX_VALUE : x );
140- }
141- }
142- };
143- }
144- };
145- }
146- }, new F <Option <Long >, F <Double , F <Double , Double >>>() {
147- public F <Double , F <Double , Double >> f (final Option <Long > seed ) {
148- return new F <Double , F <Double , Double >>() {
149- public F <Double , Double > f (final Double from ) {
150- return new F <Double , Double >() {
151- public Double f (final Double to ) {
152- final double f = min (from , to );
153- final double t = max (from , to );
154- return seed .map (fr ).orSome (new Random ()).nextDouble () * (t - f ) + f ;
155- }
156- };
157- }
158- };
159- }
127+ public static final Rand standard = new Rand (seed -> from -> to -> {
128+ final int min = min (from , to );
129+ final int max = max (from , to );
130+ final Random random = seed .map (fr ).orSome (new Random ());
131+ return (int ) ((random .nextLong () & Long .MAX_VALUE ) % (1L + max - min )) + min ;
132+ }, seed -> from -> to -> {
133+ final double min = min (from , to );
134+ final double max = max (from , to );
135+ final Random random = seed .map (fr ).orSome (new Random ());
136+ return random .nextDouble () * (max - min ) + min ;
160137 });
161138}
0 commit comments