/////////////////////////////////////////////////////////////////////////////
// ELEMENT GDI/DX Game Engine [Version 2002/3/1]
/////////////////////////////////////////////////////////////////////////////
// Original Author : 邱海峰[Southdy]
// OICQ : 359766
// EMAIL: topmud@263.net
/////////////////////////////////////////////////////////////////////////////
// DESCRIPTION :
//
// OTHER : 邱海峰创建于2002/3/1
//
// 使用此随机数生成器者请无条件保留以下版权声明:
// (C) Copyright Beman Dawes 1998. Permission to copy, use, modify, sell and
// distribute this software is granted provided this copyright notice appears
// in all copies. This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
/////////////////////////////////////////////////////////////////////////////
#pragma once /////////////////////////////////////////////////////////////////////////////
// 包含文件
/////////////////////////////////////////////////////////////////////////////
#include <cassert> /////////////////////////////////////////////////////////////////////////////
class EK_Rand { // 不要有改动这几个常量的想法,否则……打你屁屁!
enum { modulus = 2147483647L, multiplier = 48271L, validation = 399268537L, q = modulus / multiplier, r = modulus % multiplier }; // 种子数
long value; // 0 < value <= modulus
public: explicit min_rand( long seed_value=1 ) : value( seed_value ) { assert( value > 0 && value <= modulus ); }
operator long() const { return value; }
double fvalue() const { return double(value) / modulus; }
min_rand& operator=( long new_value ) { value = new_value; assert( value > 0 && value <= modulus ); return *this; }
long operator++() { value = multiplier*(value%q) - r*(value/q); if ( value <= 0 ) value += modulus; assert( value > 0 && value <= modulus ); return value; }
long operator++(int) { long temp = value; operator++(); return temp; }
long ten_thousandth() const { return validation; }
long operator()( long n ) { return operator++() % n; }
long operator()() { return operator++(); }
typedef long argument_type; typedef long result_type; }; /////////////////////////////////////////////////////////////////////////////
|