uniform_int.java

来自「网格agent平台(GAP ,Grid AgentsPlatform)开发包」· Java 代码 · 共 54 行

JAVA
54
字号
/*
 ****************************************************************************************
 * Copyright ? Giovanni Novelli
 * All Rights Reserved.
 ****************************************************************************************
 *
 * Title:        GAP Simulator
 * Description:  GAP (Grid Agents Platform) Toolkit for Modeling and Simulation
 *               of Mobile Agents on Grids
 * License:      GPL - http://www.gnu.org/copyleft/gpl.html
 *
 * Uniform_int.java
 *
 * Created on 25 August 2006, 12.00 by Giovanni Novelli
 *
 ****************************************************************************************
 *
 * $Revision$
 * $Id$
 * $HeadURL$
 *
 *****************************************************************************************
 */

package net.sf.gap.distributions;

import eduni.simjava.distributions.Sim_uniform_obj;

/**
 * A random number generator of int numbers based on the Uniform distribution
 *
 * @author Giovanni Novelli
 * @see eduni.simjava.distributions.Sim_uniform_obj
 */
public class Uniform_int extends Sim_uniform_obj {

	/** Creates a new instance of Uniform_int */
	public Uniform_int(String name) {
		super(name, 0.0, 1.0);
	}

	public int sample(int size) {
		double d = this.sample();
		int index = (int) (d * size);
		if (index < 1) {
			index = 0;
		}
		if (index >= size) {
			index = size - 1;
		}
		return index;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?