From 8bd4b0a0b15ee5e8b7ec0d468958cf49539c1b36 Mon Sep 17 00:00:00 2001 From: stephen mcquay Date: Wed, 27 Dec 2017 22:31:28 -0800 Subject: [PATCH] added random reader I thought this one might be slow but it gets 400Mb/s on my mac. --- cmd/trash/main.go | 2 ++ trash.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/cmd/trash/main.go b/cmd/trash/main.go index ef8a812..c5b64ae 100644 --- a/cmd/trash/main.go +++ b/cmd/trash/main.go @@ -25,6 +25,8 @@ func main() { r = trash.HiLo case "lohi", "55", "5": r = trash.LoHi + case "rand", "random": + r = trash.Random default: fmt.Fprintf(os.Stderr, "unsupported algorithm: %v\ntry one of 'lo(w)', 'hi(gh)', 'hilo', 'lohi', 'trash'\n", *algo) os.Exit(1) diff --git a/trash.go b/trash.go index 7a29d0b..6afe612 100644 --- a/trash.go +++ b/trash.go @@ -3,6 +3,7 @@ package trash import ( "io" + "math/rand" "time" ) @@ -12,6 +13,7 @@ func init() { Fs = &reader{0xff} HiLo = &reader{0xaa} LoHi = &reader{0x55} + Random = rand.New(rand.NewSource(time.Now().UnixNano())) } // Reader provides a steady stream of trash (non-random bytes) when read from @@ -29,6 +31,8 @@ var HiLo io.Reader // LoHi provides a steady stream of 0x55 var LoHi io.Reader +var Random io.Reader + // TimeoutReader returns a reader that returns io.EOF after dur. func TimeoutReader(dur time.Duration) io.Reader { return &timeoutReader{timeout: time.Now().Add(dur)}