📄 randomgen.java
字号:
/* * This code is from the book: * * Winder, R and Roberts, G (2000) Developing Java * Software, second edition, John Wiley & Sons. * * It is copyright (c) 2000 Russel Winder and Graham Roberts. */package SimFrameWork ;import java.util.Random ;/** * This is a utility class providing a wrapper for the JDK class * java.util.Random, giving a simple interface to random number * generation used by simulations. * A single instance of the class is created and initialised * when the class is loaded (an example of the Singleton pattern). * If a more sophisticated generator is needed, this class * will localize the effects of any changes made. * * @version 2.0 March 1999 * @author Graham Roberts */public class RandomGen { /** * Do nothing constructor that is made private to prevent * instance creation outside of the class scope. */ private RandomGen() {} /** * Generate a random integer in the range 0 to n-1 inclusive. * * @param n the upper limit of the number generated. * @return a random number in the range 0 to n-1. */ public static int getNext(int n) { return rand.nextInt(n) ; } /** * Variable used to represent the single instance. * The Random class constructor will seed the random number * generator automatically using the current time. */ private static Random rand = new Random() ;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -