From b0ea16a96d2c1a1496d8a4139ac65cd55bdf69dd Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Thu, 31 Mar 2022 16:00:04 +0200 Subject: [PATCH] Added explanatory comment in primary function --- main.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/main.cpp b/main.cpp index b9d49d3..87fd02e 100644 --- a/main.cpp +++ b/main.cpp @@ -1,11 +1,3 @@ -// -// main.cpp -// ranlin -// -// Created by Bob Polis on 05-03-15. -// Copyright (c) 2015 Thalictrum. All rights reserved. -// - #include #include #include @@ -20,9 +12,13 @@ double next_random() { } string random_line_from_file(istream& file) { + // This function selects a line from a file by reading + // the file line by line, so the file is never in memory + // as a whole. Still, the chance a line is being picked + // is equal for every line. string line; string result; - for (int nr {1}; getline(file, line); ++nr) { + for (int nr = 1; getline(file, line); ++nr) { if (next_random() * nr < 1.0) { result = line; }