-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandomwalk.cpp
40 lines (38 loc) · 866 Bytes
/
randomwalk.cpp
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
#include<iostream>
#include<cstdlib>
#include<ctime>
#include"vect.h"
int main()
{
using namespace std;
using VECTOR::Vector;
srand(time(0));
double direction;
Vector step;
Vector result(0,0);
unsigned long steps = 0;
double target;
double dstep;
cout<<"Enter target distance (q to quit)\n";
while ( cin >> target){
cout<<"Enter step length"<<endl;
if ( !(cin >> dstep))
break;
while ( result.magval() < target)
{
direction = rand()%360;
step.set(dstep,direction,'p');
result = result + step;
steps ++;
}
cout<<"After "<<steps <<" steps, the subject has the following location:\n";
cout<<result<<endl;
result.polar_mode();
cout<<"or\n"<<result<<endl;
cout<<"Average outward distance per step = "<<result.magval()/steps;
steps= 0;
result.set(0,0);
cout<<"Enter target distance(q to quit)\n";
}
cout<<"Bye\n";
}