Logo Passei Direto
Buscar
Material

Prévia do material em texto

Chapter 1.3, Problem 2E Step-by-step solution Step 1 of 1 Algorithm for Fair Random Coin Writing an algorithm to implement a fair random coin toss with equal probability of heads and tails by using the function rand (1,6). Consider the function rand (1, 6) we will get a random number ranging from 1 to 6. We will convert it in range between 0 and 1 by dividing by 4 i.e. if number is less than 3 our output will be 0 otherwise output will be 1. We are considering 1 as Tail and 0 as Head. Here input is nothing and output is either Heads or Tails with equal probability. Algorithm to find random number between 0 and 1: randomCoinToss() randomNumber = rand (1, 6)/4 return randomNumber }

Mais conteúdos dessa disciplina