How does Major League Baseball MLB create their schedules?

How does Major League Baseball MLB create their schedules?

I know the NFL has a specific formula now that locks in which teams will play each other once the regular season ends (inter-conference play is rotated in a set pattern every year); all that remains is organizing the dates and who is visiting whom. What system does MLB use? How does MLB determine how many games a team will play another team in a season? How does MLB determine what inter-league teams will play each other each season?