ROSETTA C++库是一个C++类库和例程集合

源代码在线查看: rand.cpp

软件大小: 4078 K
上传用户: Erlin
关键词: ROSETTA
下载地址: 免注册下载 普通下载 VIP

相关代码

				// Rand.cpp: implementation of the Rand class.
				//
				//////////////////////////////////////////////////////////////////////
				
				#include  // Added 980901 by Aleksander 踙rn.
				#include "../copyright.h" // Added 000323 by Aleksander 豩rn.
				#include 
				#include "Rand.h"
				
				RNG Rand::rngInstance = RNG();
				RNG * Rand::rng = NULL;
				long Rand::seed = 12345;
				int Rand::MaxInt = 0x7fff;
				
				//////////////////////////////////////////////////////////////////////
				// Construction/Destruction
				//////////////////////////////////////////////////////////////////////
				
				Rand::Rand()
				{
				}
				
				Rand::~Rand()
				{
				}
				
				double Rand::d()
				{
					if(rng == NULL){
						rng = &rngInstance;
						rng->SetSeed(Rand::seed);
					}
					return (double)rng->DrawFloat();
				}
				
				int Rand::i(int upper)
				{
					if(rng == NULL){
						rng = &rngInstance;
						rng->SetSeed(Rand::seed);
					}
					return rng->DrawInteger(0, upper);
				}
				
				void Rand::setSeed(long seed)
				{
					Rand::seed = seed;
					if(rng == NULL){
						rng = &rngInstance;
						rng->SetSeed(Rand::seed);
						Message::Debug(String("Setting random seed to ") + String::Format(Rand::seed));
					}
				}
							

相关资源