samer@0
|
1 /*
|
samer@0
|
2 * Copyright (c) 2000, Samer Abdallah, King's College London.
|
samer@0
|
3 * All rights reserved.
|
samer@0
|
4 *
|
samer@0
|
5 * This software is provided AS iS and WITHOUT ANY WARRANTY;
|
samer@0
|
6 * without even the implied warranty of MERCHANTABILITY or
|
samer@0
|
7 * FITNESS FOR A PARTICULAR PURPOSE.
|
samer@0
|
8 */
|
samer@0
|
9
|
samer@0
|
10 package samer.maths.random;
|
samer@0
|
11 import samer.core.types.*;
|
samer@0
|
12 import java.util.*;
|
samer@0
|
13
|
samer@0
|
14 public class BoundedUniform extends BaseRandom implements Observer
|
samer@0
|
15 {
|
samer@0
|
16 VDouble min = new VDouble("min",0);
|
samer@0
|
17 VDouble max = new VDouble("max",1);
|
samer@0
|
18 double a, b;
|
samer@0
|
19
|
samer@0
|
20 public String toString() { return "Uniform["+min.value+","+max.value+")"; }
|
samer@0
|
21
|
samer@0
|
22 public void dispose() { min.dispose(); max.dispose(); }
|
samer@0
|
23 public double next() { return a + b*rnd.nextDouble(); }
|
samer@0
|
24 public void next(double [] x) {
|
samer@0
|
25 for (int i=0; i<x.length; i++) x[i]=a + b*rnd.nextDouble();
|
samer@0
|
26 }
|
samer@0
|
27
|
samer@0
|
28 public BoundedUniform( double min, double max)
|
samer@0
|
29 {
|
samer@0
|
30 this();
|
samer@0
|
31 this.min.value = min; this.min.changed();
|
samer@0
|
32 this.max.value = max; this.max.changed();
|
samer@0
|
33 }
|
samer@0
|
34
|
samer@0
|
35 public BoundedUniform()
|
samer@0
|
36 {
|
samer@0
|
37 min.addObserver(this);
|
samer@0
|
38 max.addObserver(this);
|
samer@0
|
39 update(null,null);
|
samer@0
|
40 }
|
samer@0
|
41
|
samer@0
|
42 public void update(Observable o, Object oo) {
|
samer@0
|
43 a=min.value; b=max.value-min.value;
|
samer@0
|
44 }
|
samer@0
|
45 }
|