KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > util > RandomMap


1 package JSci.util;
2
3 import JSci.maths.*;
4
5 /**
6 * This class defines a random map.
7 */

8 public final class RandomMap implements Mapping, ComplexMapping {
9         private final double min,max;
10         /**
11         * A random map that generates numbers
12         * between 0.0 and 1.0.
13         */

14         public final static RandomMap MAP=new RandomMap();
15
16         /**
17         * Constructs a random map with the range [0.0,1.0].
18         */

19         public RandomMap() {
20                 this(0.0,1.0);
21         }
22         /**
23         * Constructs a random map with a specified range.
24         * @param minimum smallest random number to generate
25         * @param maximum largest random number to generate
26         */

27         public RandomMap(double minimum,double maximum) {
28                 min=minimum;
29                 max=maximum;
30         }
31         public double map(double x) {
32                 return ExtraMath.random(min, max);
33         }
34         public Complex map(Complex z) {
35                 return new Complex(map(z.real()),map(z.imag()));
36         }
37         public Complex map(double real,double imag) {
38                 return new Complex(map(real),map(imag));
39         }
40 }
41
42
Popular Tags