# Flipping a coin in R
<- function() {
coin_flip <- sample(c("Heads", "Tails"), size = 1)
outcome return(outcome)
}
coin_flip()
Skills
Coding
🟢 R
🔵 Python
# Flipping a coin in python
import random
def coin_flip():
= random.choice(["Heads", "Tails"])
outcome return outcome
coin_flip()
🟠 Fortran
! Flipping a coin with fortran subroutine
program coin_flip_program
implicit none
character(len=5) :: outcome
call coin_flip(outcome)
print *, 'The coin flip result is: ', outcome
contains
subroutine coin_flip(result)
character(len=5), intent(out) :: result
real :: rand_num
call random_seed()
call random_number(rand_num)
if (rand_num < 0.5) then
result = 'Heads'
else
result = 'Tails'
end if
end subroutine coin_flip
end program coin_flip_program