From 1b6978c6dd80b3d5f63f3a2ab4f31ff441ccb83b Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Tue, 29 Jul 2014 15:04:27 -0400 Subject: [PATCH] avoid blank lines --- randomizr.go | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/randomizr.go b/randomizr.go index 706a847..fac21bc 100644 --- a/randomizr.go +++ b/randomizr.go @@ -88,28 +88,23 @@ func (w wordBag) randomWordBelow(n int) string { func (w wordBag) wordString(n int) string { var ( buf bytes.Buffer - remaining int + remaining = n ) for { - remaining = n - buf.Len() switch { case remaining < 0: return buf.String() case remaining < 8: buf.WriteString(w.randomWordN(remaining)) - if rand.Float64() > 0.8 { - buf.WriteRune('\n') - } else { - buf.WriteRune(' ') - } default: - buf.WriteString(w.randomWordBelow(remaining)) - if rand.Float64() > 0.8 { - buf.WriteRune('\n') - } else { - buf.WriteRune(' ') - } + buf.WriteString(w.randomWordBelow(8)) + } + remaining = n - buf.Len() + if multiline && remaining > 1 && rand.Float64() > 0.98 { + buf.WriteRune('\n') + } else { + buf.WriteRune(' ') } } }