One of n lines in a file: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
No edit summary |
||
Line 16: | Line 16: | ||
;Task: |
;Task: |
||
# Create a function/method/routine called <code>one_of_n</code> that given <code>n</code>, the number of actual lines in a file, follows the algorithm above to return an integer - the line number of the line chosen from the file. <br>The number returned can vary, randomly, in each run. |
# Create a function/method/routine called <code>one_of_n</code> that given <code>n</code>, the number of actual lines in a file, follows the algorithm above to return an integer - the line number of the line chosen from the file. <br>The number returned can vary, randomly, in each run. |
||
# Use <code>one_of_n</code> in a ''simulation'' to find what |
# Use <code>one_of_n</code> in a ''simulation'' to find what would be the chosen line of a 10-line file simulated 1,000,000 times. |
||
# Print and show how many times each of the 10 lines is chosen as a rough measure of how well the algorithm works. |
# Print and show how many times each of the 10 lines is chosen as a rough measure of how well the algorithm works. |
||