[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Swarm-Support] want to see example of generating random values
From: |
Steve Railsback |
Subject: |
Re: [Swarm-Support] want to see example of generating random values |
Date: |
Fri, 25 May 2007 07:45:15 -0700 |
User-agent: |
Thunderbird 2.0.0.0 (Windows/20070326) |
Tieju MA wrote:
I want to generate random values following LogNormal distributions with
specified mean and variance, but I am very much confused about
LogNormalDistCImpl
<http://www.swarm.org/swarmdocs-2.2/refbook-java/swarm/random/LogNormalDistCImpl.html>
LogNormalDistImpl
<http://www.swarm.org/swarmdocs-2.2/refbook-java/swarm/random/LogNormalDistImpl.html>
and those interfaces they implement. I don't know how to write the Java
code.
So it will be really appreciate if someone could show me an example of
using those classes and interfaces to generate random values.
There is an example use of the *normal* (not LogNormal) distribution in
the "StupidModel" template code:
http://www.swarm.org/wiki/Software_templates
Here are code pieces, which were in the Model Swarm.
---
import swarm.random.NormalDistImpl;
---
public class StupidModelSwarm extends SwarmImpl {
// Declarations
public ListImpl bugList;
...
private NormalDistImpl bugInitSizeDist;
// Declare model parameters
public int numberOfInitialBugs = 100;
public double initialBugSizeMean = 0.1;
public double initialBugSizeSD = 0.03;
---
// For version 14, we create a normal distribution for
// initial bug sizes here, and use it in getBugInitSize
// This must be created before we create the bugs!
bugInitSizeDist = new NormalDistImpl
(this, Globals.env.randomGenerator, initialBugSizeMean,
initialBugSizeSD);
---
public double getBugInitSize() {
// In version 14, initial bug sizes are pulled randomly
double initBugSize = bugInitSizeDist.getDoubleSample();
if (initBugSize > 0.0) return initBugSize;
else return 0.0;
}
--
Steve Railsback
Lang, Railsback & Associates
Arcata, California
www.LangRailsback.com