Info
This question is closed. Reopen it to edit or answer.
Determining how many random numbers have to be drawn to get a certain sum? (Script)
1 view (last 30 days)
Show older comments
Hello everyone,
I am trying to write a 'while loop' script that determines how many random numbers have to be drawn from a uniform distribution between 0 and 1 to get a sum greater than 10. I also have to modify the script so it will repeat the experiment 1 to 1000 times until the condition of 'sum greater than 10' is met.
What I do know is that I have to use a 'while loop' and implement the 'rand' function. But I am completely lost on how to get the ball rolling on this one. Any help is much appreciated!
0 Comments
Answers (1)
Walter Roberson
on 12 Feb 2016
You can use this general structure
initialize some variables
while true
do some calculation
if some condition is satisfied based upon the calculations
break;
end
end
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!