micah wise

Greenhorn

Posts: 6

posted 1 year ago

Ok so I am a newbie to java coding and I have an assignment to do a coin flip program. No problem there, except he also wants the program to skew the results. So, in the coding we have to add a ratio or some coding to improve the chance of either heads or tails??? Help?@!?

posted 1 year ago

Michah,

A ratio (or percentage) is a good way to think of it. How are you getting the results when it is 50/50?

A ratio (or percentage) is a good way to think of it. How are you getting the results when it is 50/50?

[OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]

Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2

micah wise

Greenhorn

Posts: 6

posted 1 year ago

I tried changing your .5 to .95 to make it a really skewed coin. See this ideone example.

The result was:

Number of Heads = 92

Number of Tails = 8

What do you see not working in yours?

The result was:

Number of Heads = 92

Number of Tails = 8

What do you see not working in yours?

Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2

micah wise

Greenhorn

Posts: 6

posted 1 year ago

Got it!!! Created a whole new class and bingo....I haven't a foggy clue what was really wrong with the other just now but creating a whole new class and creating from the beginning did it!! Thanks ever so much, you confirmed that my code was likely right but something else was a miss so I went digging! My next assignment is about family probability and whether there will two boys, boy/girl or two girls. Do you think you might be able to help, I would sure appreciate it in bunches! I swear my IQ is just fine but this stuff has me just a little batty trying to get used to it and learning it!

posted 1 year ago

Welcome to

Glad to hear you got the solution , can you please post the solved code so It may also be helpful to others who perhaps have same problem.

Of course you can create a separate topic for your new problem, volunteers who knows the answer will definitely try to help you.

**CodeRanch!**Glad to hear you got the solution , can you please post the solved code so It may also be helpful to others who perhaps have same problem.

Of course you can create a separate topic for your new problem, volunteers who knows the answer will definitely try to help you.

Being programmer.

micah wise

Greenhorn

Posts: 6

posted 1 year ago

Who said this? What "boolean method"?

Me too! Could you post your code with a comment on the line(s) that are the problem?

micah wise wrote:Ok so he isn't preferential of the boolean method

Who said this? What "boolean method"?

what other way is there to represent 50 : 50 or 60 : 40 or etc??? I am really lost

Me too! Could you post your code with a comment on the line(s) that are the problem?

All things are lawful, but not all things are profitable.

posted 1 year ago

Here's what I'm guessing you mean by this: he prefers you to use a different method other than

If so, consider this:

micah wise wrote:Ok so he isn't preferential of the boolean method what other way is there to represent 50 : 50 or 60 : 40 or etc??? I am really lost

Here's what I'm guessing you mean by this: he prefers you to use a different method other than

`(rand < skewPoint)`where you change the value of

`skewPoint`to skew the results.

If so, consider this:

*Practice only makes habit, only perfect practice makes perfect.
Practice mindfully by doing the right things and doing things right.*— Junilu

[How to Ask Questions] [How to Answer Questions]

Piet Souris

Rancher

Posts: 1979

67

posted 1 year ago

That prof has a strange sense of humor in that case.

@micah

an experiment that has two possible outcomes (success/failure, 1/0, true/false, et cetera) is called a Bernoulli trial. It is characterized by one number p with 0 <= p <=1, the chance of success. A straightforward way to model this is for instance:

But sometimes it is more convenient to return either a 1 or a 0, like in

and I suppose that this is what the prof meant.

With this latter definition your flip con program becomes as simple as

There is nothing to stop one from repeating many trials in succession. If we are interested in the total number of successes, then this total is according to the so called Binomial distribution. This is exactly what you do in your flip coin code . Applications are plenty:

If we have 1000 children, what is the chance that we have more than 550 girls

if we cast 100 dice, what is the chance that 30 of 'm have either 2 or 5 eyes

if we throw a coin 1000 times and we get 650 times a head, do we still believe that head has a 50% chance?

I read that your next assignment is about boys and girls. Let me finish with a small classic problem:

A family has two children. What is the chance that both of these are boys, if we know that

* the older child is a boy

* at least one of them is a boy?

Happy coding.

@micah

an experiment that has two possible outcomes (success/failure, 1/0, true/false, et cetera) is called a Bernoulli trial. It is characterized by one number p with 0 <= p <=1, the chance of success. A straightforward way to model this is for instance:

But sometimes it is more convenient to return either a 1 or a 0, like in

and I suppose that this is what the prof meant.

With this latter definition your flip con program becomes as simple as

There is nothing to stop one from repeating many trials in succession. If we are interested in the total number of successes, then this total is according to the so called Binomial distribution. This is exactly what you do in your flip coin code . Applications are plenty:

If we have 1000 children, what is the chance that we have more than 550 girls

if we cast 100 dice, what is the chance that 30 of 'm have either 2 or 5 eyes

if we throw a coin 1000 times and we get 650 times a head, do we still believe that head has a 50% chance?

I read that your next assignment is about boys and girls. Let me finish with a small classic problem:

A family has two children. What is the chance that both of these are boys, if we know that

* the older child is a boy

* at least one of them is a boy?

Happy coding.

It is sorta covered in the JavaRanch Style Guide. |