01 /*
02 * Created on Aug 30, 2007
03 */
04 package com.x8ing.mc.distribution;
05
06 import java.util.Random;
07
08 /**
09 * Uses the functionality that java provides itself.
10 *
11 * @author Patrick Heusser
12 */
13 public class RandomDistributionConstant implements RandomDistribution {
14
15 private Random rnd = new Random();
16
17 private int rangeMin = -1;
18
19 private int rangeMax = -1;
20
21 public RandomDistributionConstant(int rangeMin, int rangeMax) {
22 super();
23 this.rangeMin = rangeMin;
24 this.rangeMax = rangeMax;
25 }
26
27 /**
28 * @see com.x8ing.mc.distribution.RandomDistribution#getNextRandomNumber()
29 */
30 public double getNextRandomNumber() {
31
32 int spread = rangeMax - rangeMin;
33
34 return rnd.nextDouble() * spread + rangeMin;
35
36 }
37
38 public int getRangeMax() {
39 return rangeMax;
40 }
41
42 public void setRangeMax(int rangeMax) {
43 this.rangeMax = rangeMax;
44 }
45
46 public int getRangeMin() {
47 return rangeMin;
48 }
49
50 public void setRangeMin(int rangeMin) {
51 this.rangeMin = rangeMin;
52 }
53
54 }
|