I'm probably being blind, nut I get the same results each time I run this console application, despite using random numbers. Can anybody kindly explain where I'm going wrong? Here is the code:
#include "stdafx.h"
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
bool bacteria(long mut, long chance){
bool result;
if (mut >= chance){
result = true;
}
else{
result = false;
}
return result;
}
int run = 1000000;//Number of iterations
int mutations;
int survival;
void domutation(){
mutations = 0;
survival = 0;
for (int i = 0; i < run; i++){
long x = rand() % 2;
long y = rand() % 1000000;
bool run = bacteria(x, y);
if (run == true){
mutations++;
}
else if (run == false) {
survival++;
}
}
cout << "Mutations: " << mutations << " Survivals: " << survival << endl;
}
int main(){
for (int x = 0; x < 10; x++){
domutation();
}
int wait;
cin >> wait;
}
Each individual iteration of domutation() produces a different result to the previous iteration, but each time I run the application, the results are always the same as they were the last time I ran it, e.g. the first iteration always produces 38 mutations, and the last always produces 52, and all in between are unchanged.
I'm sure I'm doing something dopey!
I am working in VS 2013 in Windows 8.1.
Thanks!