📄 uniform_int.java
字号:
/*
****************************************************************************************
* 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -