ITeye博客

线性同余随机算法实现

ChinaEstone · 2014-09-24 15:02 · Java技术 · 编程语言 · Markdown

package com.wistone.server.core;

public class MyRand {

	private int seed;

	public MyRand(int seed) {
		this.seed = seed;
	}

	public int next() {
		int next = (seed * 29 + 37) % 1000;
		seed = next;
		return next;
	}

	public static void main(String[] args) {
		MyRand rand = new MyRand(100);
		for (int i = 0; i < 100; i++) {
			System.out.println(rand.next());
		}
	}
}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。