⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utilities.cpp

📁 此代码经过大量使用
💻 CPP
字号:
/***************************************************************************                          utilities.cpp  -  description                             -------------------    begin                : Wed May 22 2002    copyright            : (C) 2002 by R黡iger Koch    email                : rkoch@rkoch.org ***************************************************************************//*************************************************************************** *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * ***************************************************************************/using namespace std;#include <amygdala/utilities.h>#include <math.h>#include <stdlib.h>#include <stdio.h>#include <string>#include <stdexcept>#include <sys/types.h>#include <sys/stat.h>float Utilities::GaussRand(float mean, float sigma){    // Based on code from the GNU Scientific Library    // and _Numerical Recipes in C_	float randVal, xuniRand, yuniRand;    float x, y, r2;  	do {      	// choose x,y in uniform square (-1,-1) to (+1,+1)		xuniRand = float(rand()) / float(RAND_MAX);		yuniRand = float(rand()) / float(RAND_MAX);		x = -1 + 2 * xuniRand;      	y = -1 + 2 * yuniRand;      	// see if it is in the unit circle       	r2 = x * x + y * y;    } while (r2 > 1.0 || r2 == 0);  	// Box-Muller transform  	randVal = sigma * y * sqrt(-2.0 * log(r2) / r2);	return (randVal + mean);}float Utilities::RandPercent(){    return ( float(rand()) / float(RAND_MAX) ) * 100.0;}string Utilities::itostr(int val){    string retStr;    char buf[255];    sprintf(buf, "%i", val);    retStr = buf;    return retStr;}string Utilities::ftostr(float val){    string retStr;    char buf[255];    sprintf(buf, "%f", val);    retStr = buf;    return retStr;}string Utilities::MkTempDir(){    string tmpdir;    int trials=0;    do {        tmpdir = string(P_tmpdir) + "/amygdala-" +                 itostr(1+(int) (1000.0*rand()/(RAND_MAX+1.0)));        if(++trials > 10)            throw runtime_error("cannot create temp directory: " + tmpdir);    } while (mkdir(tmpdir.c_str(), S_IRUSR | S_IWUSR | S_IXUSR));    return tmpdir;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -