I'm currently learning R and there i encountered this problem
flips <- sample(c(0,1),100, replace = TRUE, prob = c(0.3,0.7))
flips
[1] 0 1 1 1 1 0 1 0 0 0 0 1 1 0 1 1 0 1 0 0 0 1 1 1 0 1 1 1 1 0 1 1 0 1 1
[36] 0 1 1 1 1 0 1 0 1 1 1 1 0 0 0 0 0 1 0 0 1 0 0 0 1 0 1 0 1 1 1 1 1 1 1
[71] 1 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 1 0 1
sum(flips)
[1] 65
0.7 probability does not guarantee 70 heads. This is not a mistake in your code but a misunderstanding of statistics. If you run the code a few more times you will see that the result will vary, and it could even exceed 70.
A simple analogy would be that even though we know that the probability of getting heads with a fair coin is 50%, flipping 10 coins would not guarantee you 5 heads.