Beispiel #1
0
//----------------------------------------
void SingleRandom::Generate()
{
	int loop, offset;

	table_.clear();
	for(loop = range_min_; loop < range_max_; ++loop)
	{
		table_.push_back(loop);
	}

	int tem;
	RandomSeed();
	for(loop = 0; loop < table_.size(); ++loop)
	{
		offset = NormalRandom(0, table_.size() - 1) + loop;
		//offset = (rand() % (range_max_ - 1)) + loop;
		if( offset >= table_.size())
			offset -= table_.size();

		//将数字对调
		tem = table_[loop];
		table_[loop] = table_[offset];
		table_[offset] = tem;
	}
}
Beispiel #2
0
//---------------------------------------------------------------------------
int TGLM::execute(my_string* passedParams, int numPassedParams){
	//read params from input --> first two are filenames
	for(int i=0;i<numParams;++i){
		P.element(i)=passedParams[i+2].toDouble();
	}

	//write header to output file
	ofstream out;
	out.open(outputFilename.c_str());
	if(!out) throw TException("INTERNALGLM program: the output file '"+outputFilename+"' could not be opened!", _FATAL_ERROR);
	out << "Stat_1";
	for(int i=1;i<numStats;++i){
		out << "\t" << "Stat_" << i+1;
	}
	out << endl;

	for(int i=0;i<numStats;++i) e.element(i)=NormalRandom(0,1);
	e=A*e;

	//compute stats
	s=C*P+c0+e;

	//write stats
	for(int i=0;i<numStats;++i){
		out << s.element(i);
	}
	out << endl;
	out.close();
	return 1;
}
NormalRandom Random::gaussian(double mean, double variance) {
    boost::normal_distribution<> dist(mean, variance);
    return NormalRandom(seed(), dist);
}