Mercurial > hg > jslab
view src/samer/maths/random/PowerLaw.java @ 8:5e3cbbf173aa tip
Reorganise some more
author | samer |
---|---|
date | Fri, 05 Apr 2019 22:41:58 +0100 |
parents | bf79fb79ee13 |
children |
line wrap: on
line source
/* * Copyright (c) 2000, Samer Abdallah, King's College London. * All rights reserved. * * This software is provided AS iS and WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. */ package samer.maths.random; import samer.core.types.*; import java.util.*; /* * Generates random numbers from a single-sider power-law * with a lower cut-off, but no upper cut-off. The * exponent must therefore be strictly less than 1. */ public class PowerLaw extends BaseRandom implements Observer { VDouble min = new VDouble("min",1); VDouble D = new VDouble("exponent",1); double a, b; public void dispose() { min.dispose(); D.dispose(); } public double next() { return a*Math.pow(rnd.nextDouble(),b); } public PowerLaw() { min.addObserver(this); D.addObserver(this); update(null,null); } public void update(Observable o, Object oo) { a=min.value; b=-1/D.value; } }