I'm trying to generate steps for a drunk man who is 100 steps from home it takes for him to get home. He has a 1/3 probability to take position-= and 2/3 to take position+=. But my code just keeps outputting 100 steps. I'm not sure what I did wrong
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
int randomStep(int position);
int main() {
srand(time(NULL));
int position = 0, countSteps = 0;
const int HOME = 100;
do { // condition is evaluated afterthe execution of the statement
position = randomStep(position);
countSteps++;//Counting number of steps to reach home
} while (position < HOME);
cout << "No of Steps to reach home : " << countSteps << endl;
return 0;
}
int randomStep(int position) { //will return the current position of the drunked person
int randomnum = ((rand()) / (RAND_MAX)); // Generating the random number between 0 and 1
if (randomnum < (1/3)) { // if random number is < 1/3, decrease position by 1
position -= 1;
}
else { // If random number is greater than 1/3 then increase the position by 1
position += 1;
}
return position;
}