File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed
Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,8 @@ import (
1010)
1111
1212func main () {
13-
13+ var total int64
14+ var emitted int64
1415 if len (os .Args ) != 2 {
1516 fmt .Fprintf (os .Stderr , "invalid argument. use a fraction to sample between 0.0 (no sampling) and 1.0 (100% sampling)" )
1617 os .Exit (1 )
@@ -25,13 +26,17 @@ func main() {
2526 rand .Seed (time .Now ().UnixNano ())
2627 scanner := bufio .NewScanner (os .Stdin )
2728 for scanner .Scan () {
29+ total += 1
2830 if target < rand .Float64 () {
2931 continue
3032 }
33+ emitted += 1
3134 fmt .Printf ("%q" , scanner .Text ()) // Println will add back the final '\n'
3235 }
3336 if err := scanner .Err (); err != nil {
34- fmt .Fprintln (os .Stderr , "reading standard input:" , err )
37+ fmt .Fprintln (os .Stderr , "Error reading standard input:" , err )
3538 os .Exit (2 )
3639 }
40+
41+ fmt .Fprintf (os .Stderr , "Total of %d lines. Sampled to %d\n " , total , emitted )
3742}
You can’t perform that action at this time.
0 commit comments