SlideShare a Scribd company logo
1 of 2
Download to read offline
tools.cpp
#include "tools.hpp"
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdlib>
void ProgressBar(int it, int num_iterations) {
std::cout << "r" << (double)it * 100 / num_iterations + 1 << "%" <<
std::flush;
}
std::string IntToString(int i) {
if (i < 0)
{
i = i*(-1);
}
int lenght = int(log(i+1)/log(10)+1);
char buffer[lenght];
sprintf(buffer, "%d", i);
return buffer;
}
bool BernoulliDistr(double P) {
double rnd = drand48();
if (rnd < P) return true;
else return false;
}
int Distance(int x1, int y1, int x2, int y2, int grid_size) {
int dx = fabs(x1 - x2);
if (dx > grid_size/2) dx = grid_size - dx;
int dy = fabs(y1 - y2);
if (dy > grid_size/2) dy = grid_size - dy;
return dx + dy;
}
double NormalDistr(double my, double sigma) {
double u = drand48();
double v = drand48();
double snormal = cos(2*3.141592654*u)*sqrt(-2*log(v));
return sigma*snormal+my;
}
double LogNormal(double ev, double var) {
double sigma = sqrt(log(var/(ev*ev) + 1));
double my = log(ev) - sigma*sigma / 2;
Seite 1
tools.cpp
return exp(NormalDistr(my, sigma));
}
Seite 2

More Related Content

What's hot

Program of bar 3 d
Program of bar 3 dProgram of bar 3 d
Program of bar 3 d
sonamr123
 
Programa.eje
Programa.ejePrograma.eje
Programa.eje
guapi387
 

What's hot (18)

D vs OWKN Language at LLnagoya
D vs OWKN Language at LLnagoyaD vs OWKN Language at LLnagoya
D vs OWKN Language at LLnagoya
 
week-5x
week-5xweek-5x
week-5x
 
เฉลยแบบฝึกหัดบทที่ 1
เฉลยแบบฝึกหัดบทที่ 1เฉลยแบบฝึกหัดบทที่ 1
เฉลยแบบฝึกหัดบทที่ 1
 
Sol10
Sol10Sol10
Sol10
 
Program of bar 3 d
Program of bar 3 dProgram of bar 3 d
Program of bar 3 d
 
Conversion of data types in java
Conversion of data types in javaConversion of data types in java
Conversion of data types in java
 
1
11
1
 
Hotel Management In C++
Hotel Management In C++Hotel Management In C++
Hotel Management In C++
 
Data Structure - 2nd Study
Data Structure - 2nd StudyData Structure - 2nd Study
Data Structure - 2nd Study
 
C++ Programming - 14th Study
C++ Programming - 14th StudyC++ Programming - 14th Study
C++ Programming - 14th Study
 
Oop lab report
Oop lab reportOop lab report
Oop lab report
 
Bubble sort
Bubble sortBubble sort
Bubble sort
 
MFC Cosinus
MFC CosinusMFC Cosinus
MFC Cosinus
 
C- Programs - Harsh
C- Programs - HarshC- Programs - Harsh
C- Programs - Harsh
 
Programa.eje
Programa.ejePrograma.eje
Programa.eje
 
Groovify your java code by hervé roussel
Groovify your java code by hervé rousselGroovify your java code by hervé roussel
Groovify your java code by hervé roussel
 
Bubble Sort
Bubble SortBubble Sort
Bubble Sort
 
Array using recursion
Array using recursionArray using recursion
Array using recursion
 

Viewers also liked (13)

Statistics.cpp
Statistics.cppStatistics.cpp
Statistics.cpp
 
Dpsm simu.hpp
Dpsm simu.hppDpsm simu.hpp
Dpsm simu.hpp
 
Could humans recognize odor by phonon assisted tunneling
Could humans recognize odor by phonon assisted tunnelingCould humans recognize odor by phonon assisted tunneling
Could humans recognize odor by phonon assisted tunneling
 
Dpsm simu.cpp
Dpsm simu.cppDpsm simu.cpp
Dpsm simu.cpp
 
Tools.hpp
Tools.hppTools.hpp
Tools.hpp
 
Electron transport in one dimensional nanosystems
Electron transport in one dimensional nanosystemsElectron transport in one dimensional nanosystems
Electron transport in one dimensional nanosystems
 
Structure-odor relations: a modern perspective
Structure-odor relations: a modern perspectiveStructure-odor relations: a modern perspective
Structure-odor relations: a modern perspective
 
Statstockprog
StatstockprogStatstockprog
Statstockprog
 
Dynamical symmetry breaking in vibration-assisted transport through nanostruc...
Dynamical symmetry breaking in vibration-assisted transport through nanostruc...Dynamical symmetry breaking in vibration-assisted transport through nanostruc...
Dynamical symmetry breaking in vibration-assisted transport through nanostruc...
 
Smell in real noses: how the environment changes vibrations
Smell in real noses: how the environment changes vibrationsSmell in real noses: how the environment changes vibrations
Smell in real noses: how the environment changes vibrations
 
Statistics.hpp
Statistics.hppStatistics.hpp
Statistics.hpp
 
Main.cpp
Main.cppMain.cpp
Main.cpp
 
Econophysics
EconophysicsEconophysics
Econophysics
 

Similar to Tools.cpp

Ejercicios de programacion
Ejercicios de programacionEjercicios de programacion
Ejercicios de programacion
Jeff Tu Pechito
 
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointers
vinay arora
 
C basics
C basicsC basics
C basics
MSc CST
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
Er Ritu Aggarwal
 

Similar to Tools.cpp (20)

Cpds lab
Cpds labCpds lab
Cpds lab
 
Ejercicios de programacion
Ejercicios de programacionEjercicios de programacion
Ejercicios de programacion
 
include.docx
include.docxinclude.docx
include.docx
 
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointers
 
oodp elab.pdf
oodp elab.pdfoodp elab.pdf
oodp elab.pdf
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
 
Lập trình C
Lập trình CLập trình C
Lập trình C
 
Lab Question
Lab QuestionLab Question
Lab Question
 
C basics
C basicsC basics
C basics
 
Blocks+gcd入門
Blocks+gcd入門Blocks+gcd入門
Blocks+gcd入門
 
Go vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoFGo vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoF
 
C programming function
C  programming functionC  programming function
C programming function
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
VTU Network lab programs
VTU Network lab   programsVTU Network lab   programs
VTU Network lab programs
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C Code
 
C++ Lambda and concurrency
C++ Lambda and concurrencyC++ Lambda and concurrency
C++ Lambda and concurrency
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
C questions
C questionsC questions
C questions
 
String Manipulation Function and Header File Functions
String Manipulation Function and Header File FunctionsString Manipulation Function and Header File Functions
String Manipulation Function and Header File Functions
 

More from Vorname Nachname

More from Vorname Nachname (12)

Leni souza
Leni souzaLeni souza
Leni souza
 
Alien life forms
Alien life formsAlien life forms
Alien life forms
 
Spaceengine2
Spaceengine2Spaceengine2
Spaceengine2
 
Structural Language
Structural LanguageStructural Language
Structural Language
 
Language
LanguageLanguage
Language
 
Spaceengine2
Spaceengine2Spaceengine2
Spaceengine2
 
Spaceengine
SpaceengineSpaceengine
Spaceengine
 
Topology and Electrostatics
Topology and Electrostatics Topology and Electrostatics
Topology and Electrostatics
 
calculation of currents in nanowires
calculation of currents in nanowirescalculation of currents in nanowires
calculation of currents in nanowires
 
Summerpoject 2005
Summerpoject 2005Summerpoject 2005
Summerpoject 2005
 
Aspelmeyer
AspelmeyerAspelmeyer
Aspelmeyer
 
Arndt matter wave interferometry
Arndt matter wave interferometry Arndt matter wave interferometry
Arndt matter wave interferometry
 

Recently uploaded

CYTOGENETIC MAP................ ppt.pptx
CYTOGENETIC MAP................ ppt.pptxCYTOGENETIC MAP................ ppt.pptx
CYTOGENETIC MAP................ ppt.pptx
Silpa
 
biology HL practice questions IB BIOLOGY
biology HL practice questions IB BIOLOGYbiology HL practice questions IB BIOLOGY
biology HL practice questions IB BIOLOGY
1301aanya
 
Reboulia: features, anatomy, morphology etc.
Reboulia: features, anatomy, morphology etc.Reboulia: features, anatomy, morphology etc.
Reboulia: features, anatomy, morphology etc.
Silpa
 
development of diagnostic enzyme assay to detect leuser virus
development of diagnostic enzyme assay to detect leuser virusdevelopment of diagnostic enzyme assay to detect leuser virus
development of diagnostic enzyme assay to detect leuser virus
NazaninKarimi6
 
Phenolics: types, biosynthesis and functions.
Phenolics: types, biosynthesis and functions.Phenolics: types, biosynthesis and functions.
Phenolics: types, biosynthesis and functions.
Silpa
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
The Mariana Trench remarkable geological features on Earth.pptx
The Mariana Trench remarkable geological features on Earth.pptxThe Mariana Trench remarkable geological features on Earth.pptx
The Mariana Trench remarkable geological features on Earth.pptx
seri bangash
 

Recently uploaded (20)

Clean In Place(CIP).pptx .
Clean In Place(CIP).pptx                 .Clean In Place(CIP).pptx                 .
Clean In Place(CIP).pptx .
 
PATNA CALL GIRLS 8617370543 LOW PRICE ESCORT SERVICE
PATNA CALL GIRLS 8617370543 LOW PRICE ESCORT SERVICEPATNA CALL GIRLS 8617370543 LOW PRICE ESCORT SERVICE
PATNA CALL GIRLS 8617370543 LOW PRICE ESCORT SERVICE
 
Genome sequencing,shotgun sequencing.pptx
Genome sequencing,shotgun sequencing.pptxGenome sequencing,shotgun sequencing.pptx
Genome sequencing,shotgun sequencing.pptx
 
CYTOGENETIC MAP................ ppt.pptx
CYTOGENETIC MAP................ ppt.pptxCYTOGENETIC MAP................ ppt.pptx
CYTOGENETIC MAP................ ppt.pptx
 
biology HL practice questions IB BIOLOGY
biology HL practice questions IB BIOLOGYbiology HL practice questions IB BIOLOGY
biology HL practice questions IB BIOLOGY
 
module for grade 9 for distance learning
module for grade 9 for distance learningmodule for grade 9 for distance learning
module for grade 9 for distance learning
 
Use of mutants in understanding seedling development.pptx
Use of mutants in understanding seedling development.pptxUse of mutants in understanding seedling development.pptx
Use of mutants in understanding seedling development.pptx
 
Genetics and epigenetics of ADHD and comorbid conditions
Genetics and epigenetics of ADHD and comorbid conditionsGenetics and epigenetics of ADHD and comorbid conditions
Genetics and epigenetics of ADHD and comorbid conditions
 
Atp synthase , Atp synthase complex 1 to 4.
Atp synthase , Atp synthase complex 1 to 4.Atp synthase , Atp synthase complex 1 to 4.
Atp synthase , Atp synthase complex 1 to 4.
 
300003-World Science Day For Peace And Development.pptx
300003-World Science Day For Peace And Development.pptx300003-World Science Day For Peace And Development.pptx
300003-World Science Day For Peace And Development.pptx
 
Reboulia: features, anatomy, morphology etc.
Reboulia: features, anatomy, morphology etc.Reboulia: features, anatomy, morphology etc.
Reboulia: features, anatomy, morphology etc.
 
development of diagnostic enzyme assay to detect leuser virus
development of diagnostic enzyme assay to detect leuser virusdevelopment of diagnostic enzyme assay to detect leuser virus
development of diagnostic enzyme assay to detect leuser virus
 
Phenolics: types, biosynthesis and functions.
Phenolics: types, biosynthesis and functions.Phenolics: types, biosynthesis and functions.
Phenolics: types, biosynthesis and functions.
 
Thyroid Physiology_Dr.E. Muralinath_ Associate Professor
Thyroid Physiology_Dr.E. Muralinath_ Associate ProfessorThyroid Physiology_Dr.E. Muralinath_ Associate Professor
Thyroid Physiology_Dr.E. Muralinath_ Associate Professor
 
Proteomics: types, protein profiling steps etc.
Proteomics: types, protein profiling steps etc.Proteomics: types, protein profiling steps etc.
Proteomics: types, protein profiling steps etc.
 
Call Girls Ahmedabad +917728919243 call me Independent Escort Service
Call Girls Ahmedabad +917728919243 call me Independent Escort ServiceCall Girls Ahmedabad +917728919243 call me Independent Escort Service
Call Girls Ahmedabad +917728919243 call me Independent Escort Service
 
Zoology 5th semester notes( Sumit_yadav).pdf
Zoology 5th semester notes( Sumit_yadav).pdfZoology 5th semester notes( Sumit_yadav).pdf
Zoology 5th semester notes( Sumit_yadav).pdf
 
FAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and SpectrometryFAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
The Mariana Trench remarkable geological features on Earth.pptx
The Mariana Trench remarkable geological features on Earth.pptxThe Mariana Trench remarkable geological features on Earth.pptx
The Mariana Trench remarkable geological features on Earth.pptx
 

Tools.cpp

  • 1. tools.cpp #include "tools.hpp" #include <iostream> #include <fstream> #include <cmath> #include <cstdlib> void ProgressBar(int it, int num_iterations) { std::cout << "r" << (double)it * 100 / num_iterations + 1 << "%" << std::flush; } std::string IntToString(int i) { if (i < 0) { i = i*(-1); } int lenght = int(log(i+1)/log(10)+1); char buffer[lenght]; sprintf(buffer, "%d", i); return buffer; } bool BernoulliDistr(double P) { double rnd = drand48(); if (rnd < P) return true; else return false; } int Distance(int x1, int y1, int x2, int y2, int grid_size) { int dx = fabs(x1 - x2); if (dx > grid_size/2) dx = grid_size - dx; int dy = fabs(y1 - y2); if (dy > grid_size/2) dy = grid_size - dy; return dx + dy; } double NormalDistr(double my, double sigma) { double u = drand48(); double v = drand48(); double snormal = cos(2*3.141592654*u)*sqrt(-2*log(v)); return sigma*snormal+my; } double LogNormal(double ev, double var) { double sigma = sqrt(log(var/(ev*ev) + 1)); double my = log(ev) - sigma*sigma / 2; Seite 1