Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int xPosCalc(int sigmaMatter, int muMatter, int sigmaAntimatter, int muAntimatter, int xRand)
{
xRand = rand() % 36;
int xPosMatter = (1/(sigmaMatter*sqrt(2*M_PI)))*exp(-((xRand-muMatter)*(xRand-muMatter))/(2*(sigmaMatter*sigmaMatter)));
int xPosAntimatter = (1/(sigmaAntimatter*sqrt(2*M_PI)))*exp(-((xRand-muAntimatter)*(xRand-muAntimatter))/(2*(sigmaAntimatter*sigmaAntimatter)));
int xProbability = xPosMatter * xPosAntimatter;
printf("Random variable is: %d", xRand);
printf("\nProbability is: %d", xProbability);
}
int main(void)
{
int sigmaMatter = 4.2;
int muMatter = 27.0;
int sigmaAntimatter = 6.0;
int muAntimatter = 17.0;
int xRand = 0.0;
xPosCalc(sigmaMatter, muMatter, sigmaAntimatter, muAntimatter, xRand);
}
The problem is my random variable (restricted from 0-35) comes out as 29 every time I run the program, not a random number like I need. I'm guessing this is either a problem with the way I'm passing my variables (something I'm still learning) or a stack error.
I know my math can be simplified, but I don't think that is what's causing the current issue.