Added explanatory comment in primary function
This commit is contained in:
parent
4e656db597
commit
b0ea16a96d
14
main.cpp
14
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 <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user