Hey all,
I'm a computer science major. I've been programming (mostly in C/C++) for over 6 years now. I'm also currently 520 eggs into a hunt for a shiny Yanma/Yanmega. This is my first Masuda method based hunt for a shiny, so I have no prior experience with this method. We all know it is 1/1366 or 6/8192, but I wasn't content with that. I just finished writing a short program that lets you simulate the Masuda method by hatching eggs.
The program lets you input the number of simulations you want to run (i.e. the number of shiny hunts you want it to simulate), and then will perform a simulated shiny hunt for you. Once it comes across a shiny, it will record how many eggs it took to get it, and move on to the next simulation. After it has finished the number of simulations you input, it will average the results and tell you the average number of eggs it took to find a shiny during each simulation. It will also tell you how many eggs it took each time it finishes a simulated hunt, so you can see the number of eggs for each individual hunt too.
For anyone who is interested, here is the source code...
Code:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
//SEED THE RNG
srand ( time(NULL) );
//GET INPUT
cout << "Enter the desired number of simulations: ";
int num = -1;
cin >> num;
cout << endl << "Working..." << endl << endl;
//DEFINE DYNAMIC ARRAY OF EGGS WHICH WERE SHINY
int * values = new int [num];
for(int i = 0, egg = 1; i < num; egg++)
{
/*
Keep two variables, i = 0 and egg = 1.
i is our counter variable, and while i < num,
the loop continues running. egg is the number
of eggs we have hatched in the current simulation.
*/
int RNG = rand() % 8192; //between 0 and 8191
if(RNG >= 0 && RNG <= 5) //if the number is 0, 1, 2, 3, 4, or 5 (Masuda Method), then...
{
values[i] = egg; //...assign the number of eggs it took into values...
i++; //...increase i...
cout << "Simulation #" << i << ": Shiny after " << egg << " eggs." << endl; //...print the results...
egg = 0; //... and reset egg to 0. When the loop reinitiates, it will boost egg back up to the initial value of 1.
}
}
/*
Now values contains num number of values, which are the number of eggs it took
during each simulation to get a shiny. Now we just have to average them and print.
*/
int avg = 0;
for(int i = 0; i < num; i++)
{
avg += values[i];
}
avg /= num;
cout << endl << "The average number of eggs it took to get" << endl << "a shiny during " << num << " simulations was " << avg << " eggs." << endl << endl;
delete [] values;
return 0;
}
I just finished running the program where the number of simulations was 25,000; that means it successfully found shinies in 25,000 (twenty-five thousand) unique hunts, and recorded how many eggs each one took. The average number of eggs it took according to the program was 1370 eggs. This is of course only 4 eggs bigger than the statistical average of 1366.
Quite frequently, I notice hunts where it was a very small number of eggs to find a shiny, and hunts where the number of eggs was 2000 to 4000 and up. Just eyeballing it, it seems the average is somewhere in the high hundreds to low thousands, but the statistical average of 1366 is pretty accurate, as the program verifies.
Hopefully anyone else out there who knows C/C++ will find this interesting or useful. I had fun writing it. I'm going back to my shiny Yanma hunt; good luck everyone.