From 05c4ee3665445eadf094ccab395518e992c337d4 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sat, 30 Apr 2016 20:06:48 +0200 Subject: Implement `--seed` argument Enables users to customize the seed used for the pseudorandom number generator. --- justify.cc | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'justify.cc') diff --git a/justify.cc b/justify.cc index c417dfd..9115d83 100644 --- a/justify.cc +++ b/justify.cc @@ -23,6 +23,11 @@ boost::optional input( boost::program_options::value(), "Number of spaces to be prepended on each line" ) + ( + "seed", + boost::program_options::value(), + "Seed for pseudorandomly distributing missing spaces" + ) ; boost::program_options::variables_map variables; @@ -51,8 +56,9 @@ bool process(const boost::program_options::variables_map& variables) { std::cout.sync_with_stdio(false); std::cin.sync_with_stdio(false); - std::uint8_t line_length = 60; - std::uint8_t line_offset = 0; + std::uint8_t line_length = 60; + std::uint8_t line_offset = 0; + std::uint32_t seed = 3473018784; if ( variables.count("length") ) { const int user_length = variables["length"].as(); @@ -78,7 +84,11 @@ bool process(const boost::program_options::variables_map& variables) { } } - justify::LineAccumulator acc{line_length, line_offset}; + if ( variables.count("seed") ) { + seed = variables["seed"].as(); + } + + justify::LineAccumulator acc{line_length, line_offset, seed}; std::string token; while ( std::cin.good() ) { -- cgit v1.2.3