So I am tasked with using a rand function to generate many random numbers between 0-1.
After doing so and storing them in an array, I have to add each element until the sum exceeds 1, then stop there.
Ex: Say x = rand(1, 6) generates (0.12, 0.44, 0.33, 0.32, 0.55, 0.19). I would need sum up just 0.12, 0.44, 0.33, and 0.32.
sum(x) would not work as that just sums of all the generated numbers. I need it to stop immediately after it exceeds 1.
I believe I would need to use the while loop…
Best Answer