random.cpp
来自「基于GPS的多目标优化及动态多目标优化源代码 里面 包含MOP, DMOP的程序」· C++ 代码 · 共 50 行
CPP
50 行
// Random.cpp: implementation of the CRandom class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "RTDMOEA.h"
#include "Random.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
int CRandom::Seed=0;
CRandom::CRandom()
{
RandomInit();
}
CRandom::~CRandom()
{
}
void CRandom::RandomInit()
{
Seed= (int)time(NULL);
RandomInit(Seed);
}
void CRandom::RandomInit(int seed)
{
Seed=seed;
srand(Seed);
}
double CRandom::Random(double m_Start, double m_End)
{
return m_Start + (m_End - m_Start) * rand() /RAND_MAX;
}
int CRandom::Random(int m_Start, int m_End) //[m_Start , m_End]
{
return (m_Start + rand() % (m_End -m_Start+1));
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?