samer@0: /* samer@0: * Copyright (c) 2000, Samer Abdallah, King's College London. samer@0: * All rights reserved. samer@0: * samer@0: * This software is provided AS iS and WITHOUT ANY WARRANTY; samer@0: * without even the implied warranty of MERCHANTABILITY or samer@0: * FITNESS FOR A PARTICULAR PURPOSE. samer@0: */ samer@0: samer@0: package samer.maths.random; samer@0: import samer.core.types.*; samer@0: import java.util.*; samer@0: samer@0: /* samer@0: * Generates random numbers from a single-sider power-law samer@0: * with a lower cut-off, but no upper cut-off. The samer@0: * exponent must therefore be strictly less than 1. samer@0: */ samer@0: public class PowerLaw extends BaseRandom implements Observer samer@0: { samer@0: VDouble min = new VDouble("min",1); samer@0: VDouble D = new VDouble("exponent",1); samer@0: double a, b; samer@0: samer@0: public void dispose() { min.dispose(); D.dispose(); } samer@0: public double next() { return a*Math.pow(rnd.nextDouble(),b); } samer@0: samer@0: public PowerLaw() samer@0: { samer@0: min.addObserver(this); samer@0: D.addObserver(this); samer@0: update(null,null); samer@0: } samer@0: samer@0: public void update(Observable o, Object oo) { samer@0: a=min.value; samer@0: b=-1/D.value; samer@0: } samer@0: }