-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFST_first_step_time.cpp
More file actions
52 lines (42 loc) · 876 Bytes
/
FST_first_step_time.cpp
File metadata and controls
52 lines (42 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//Vamos a modificar el metodo para modelar tiempo medio de primer paso de la probabilidad de T 0->1
#include<cstdlib>
#include<fstream> //Libreria para grabar cosas en archivos
#include<iostream>
using namespace std;
int Coin(double p){
double val = 1.0*rand()/RAND_MAX;
int out;
if (val<=p){
out = 1;
}
else{
out = 0;
}
return out;
}
int main(){
ofstream Results ("T 0-> 1.dat");
srand(time(NULL)); //En la semilla, ponemos el tiempo para generar numeros aleatorios.
//Definimos la posicion inicial
int pos = 0;
//Definimos el tiempo
int t = 0;
//Definimos la probabilidad inicia
double p = 0.01;
for(int j; j <= 50; j += 1)
{
for(int i = 0; i<=10000; i++){
while(pos == 0){
pos += Coin(p);
t += 1;
}
Results<<p<<" "<<t<<endl;
t = 0;
pos = 0;
}
p += 0.01;
}
cout<<"Done"<<endl;
Results.close();
return 0;
}