jeudi 24 mai 2018

Double Coin Toss

If we have to toss two coins.
Do we need two random variables

Random gen1 = new Random();
Random gen2 = new Random();
int firstCoinToss = gen1.nextInt(2);
int secondCoinToss = gen2.nextInt(2);

Or I can do this with one

Random gen1 = new Random();
int firstCoinToss = gen1.nextInt(2);
int secondCoinToss = gen1.nextInt(2);

I am confused because we use two coins and toss should be independent.
So if we are using how it could be independent.
If we have to use one instance, when there will be need for two instances?

[Edit:] -> the both coin should be tossed 100 times and then we have to check how many tail or head occurred.




Aucun commentaire:

Enregistrer un commentaire