#randomly select 20,000 numbers between 0 and 1
B <- runif(10000, min = 0, max = 1)
head(B)## [1] 0.9661127 0.2874410 0.5546079 0.5063111 0.8729753 0.2976092
C <- runif(10000, min = 0, max = 1)
head(C)## [1] 0.02010106 0.54572742 0.43033592 0.89223379 0.33233312 0.32323655
head(B+C)## [1] 0.9862138 0.8331684 0.9849438 1.3985449 1.2053084 0.6208458
All values of B and C are between 0 and 1 and sum of the probabilites of each value in B and C will equal 1.
a <- sum((B+C) < .5)/10000
print(paste("The probability that B+C will be less than 1/2 is",a))## [1] "The probability that B+C will be less than 1/2 is 0.1259"
b <- (sum((B*C) < .5)/10000)
print(paste("The probability that B*C will be less than 1/2 is",b))## [1] "The probability that B*C will be less than 1/2 is 0.8437"
c <- sum(abs((B-C)) < .5)/10000
print(paste("The probability that |B-C| will be less than 1/2 is",c))## [1] "The probability that |B-C| will be less than 1/2 is 0.7489"
x <- 0
for(i in 1:10000){
if(max(c(B[i],C[i])) < 0.5){
x = x+1
}
}
d <- x/10000
print(paste("The probability that max{B,C} will be less than 1/2 is",d))## [1] "The probability that max{B,C} will be less than 1/2 is 0.2532"
x <- 0
for(i in 1:10000){
if(min(c(B[i],C[i])) < 0.5){
x = x+1
}
}
e <- x/10000
print(paste("The probability that min{B,C} will be less than 1/2 is",e))## [1] "The probability that min{B,C} will be less than 1/2 is 0.7532"