I love it when a comment chain has embedded R code in it!
The code above simulates the fully invested case, where you are flipping coins. If you rebalance to half invested, half of the assets in your pocket (risk free), then you need to rerun the above code with the parameters "sample(c(1.5,0.75)" because you can only gain 50% and only loose 25% each period.
Now the distribution is centered on a positive number. Indeed if you calculate the median of terminal.wealth in the fully invested case, the median is 1 (indicating no growth). In the second case, the median is a large number (indicating growth). In both cases, the means are very large numbers, skewed by the outlier cases where there happen to be many more heads than tails.