Baseball Simulator Program

Hey guys! First time post. I have a question:

First, I'm "semi" new to Java. I've written a number of programs, mainly simple ones to get totally comfortable with console before I move more into what I'm in with JFrame and GUI stuff.

I want to just have the console print out the outcome of atbats, but I want to use, say if Ryan Howard was at the plate and Cliff Lee was pitching. I want weighted randomness, I guess is what I'm asking.

Is there a way to add weight to the Math.random() function so that Ryan Howard doesn't hit .400 with 2 homeruns?

Thanks guys!

Re: Baseball Simulator Program

But two times at bat with two home runs **is** .400. However, you could make it more meaningful by working in the number of times at bat.

Regards,

Jim

Re: Baseball Simulator Program

Quote:

Originally Posted by

**jim829** But two times at bat with two home runs **is** .400. However, you could make it more meaningful by working in the number of times at bat.

Regards,

Jim

I think my main question is, how do the baseball simulators like OOTP work? I was trying to program just a simple one to get a more sophisticated win-loss record. But I can't see how they're programmed, or what kind of math they're using.

Is there a way to get a random number that will be influenced by a player's overall and past/recent performance?

Re: Baseball Simulator Program

I don't know about OOTP. If you want to calculate what a hitters average is it is essentially number of hits divided by number of times at bat. If you have a fictitious batter in a game and you want to see if the batter gets a hit or not. Then just generate a number between 0 and 1. If the number is less than or equal to the batter's average, he gets a hit. If greater than he doesn't. You could also work in home run stats and rbi stats too.

Regards,

Jim

Re: Baseball Simulator Program

Quote:

Originally Posted by

**jim829** I don't know about OOTP. If you want to calculate what a hitters average is it is essentially number of hits divided by number of times at bat. If you have a fictitious batter in a game and you want to see if the batter gets a hit or not. Then just generate a number between 0 and 1. If the number is less than or equal to the batter's average, he gets a hit. If greater than he doesn't. You could also work in home run stats and rbi stats too.

Regards,

Jim

I already know how to calculate the statistics but you helped me out TONS with the last part. That's working beautifully! Thanks a bunch