RandomGenerator

来源:互联网 发布:淘宝网护肩羽绒服 编辑:程序博客网 时间:2024/05/04 10:24
package edu.hust.imageviewer.util;

import java.util.Random;
 
 /**
  * RandomGenerator is a generator for random in the system,<br />
  * the default seed is the tms of the system.
  * @author quickpoint
  * @version 1.0 2006-05-01
  */
 public class RandomGenerator {

    // random generator
    private static Random random = new Random(System.currentTimeMillis());
   
    /**
     *  Constructor
     */
    private RandomGenerator() {
        // nothing
    }
   
    /**
     *  Set seed
     *  @param aSeed a seed provided.
     */
    public static void setSeed( long aSeed ) {
        random = new Random( aSeed );
    }
   
    /**
     *  Generate an integer
     *  @return integer random number
     */
    public static int nextInt() {
        return random.nextInt();
    }
   
    /**
     *  Generate an integer with scope
     *  @return integer random number within the scope
     */
    public static int nextInt( int scope) {
        return random.nextInt( scope );
    }
   
    /**
     *  Generate a long
     *  @return long random number
     */
    public static long nextLong() {
        return random.nextLong();
    }
 }
原创粉丝点击