reset password
Author Message
vmarti12
Posts: 17
Posted 22:47 Oct 06, 2012 |

I was wondering if anyone could give me a hint as to how to make my coins random. I have my full program set and running but I'm assigning the outcome rather than having them random. Help please?

rframe
Posts: 18
Posted 22:53 Oct 06, 2012 |

I would check the Math class.  There may be a function in there that would allow you to choose randomly if the coin was head or tails.

vmarti12
Posts: 17
Posted 23:31 Oct 06, 2012 |

I use Math.random()

I just don't know it I'm supposed to have heads and tails equalled to be something.

rframe
Posts: 18
Posted 23:36 Oct 06, 2012 |

There are probably many ways you can use a random number to determine if the coin is heads or tails, you can also use the math function to get int values up to a certain number. Without giving you the answer I think this may put you on the right track

kevinmowers@yahoo.com
Posts: 49
Posted 13:36 Oct 08, 2012 |

int randomInt = 2 + (int)(Math.random() * ((10-2) + 1));


This generates a number between 2 and 10, which includes 10 in the random numbers.

A coin has two sides, so use 0 for heads and 1 for tails.