Chinaunix首页 | 论坛 | 博客
  • 博客访问: 460837
  • 博文数量: 107
  • 博客积分: 6073
  • 博客等级: 准将
  • 技术积分: 790
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-14 15:34
文章分类

全部博文(107)

文章存档

2010年(1)

2009年(106)

分类: C/C++

2009-08-28 23:57:34

/////////////////////////////////////////////////////////////////////////////

// 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;
};
/////////////////////////////////////////////////////////////////////////////
//在boost里看到的绝对好东东。
//在保留原作者版权声明的条件下可以随意使用 :)

阅读(944) | 评论(0) | 转发(0) |
0

上一篇:A*寻路初探

下一篇:STL中的排序算法

给主人留下些什么吧!~~