File: example3.go

package info (click to toggle)
golang-github-cznic-mathutil 0.0~git20150605.0.a804f0f-1~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 656 kB
  • sloc: makefile: 40
file content (43 lines) | stat: -rw-r--r-- 783 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright (c) 2011 CZ.NIC z.s.p.o. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// blame: jnml, labs.nic.cz

// +build ignore

package main

import (
	"bufio"
	"flag"
	"log"
	"math/rand"
	"os"
)

/*

$ # Usage e.g.:
$ go run example3.go -max 1024 > rand.dat # generate 1kB of "random" data

*/
func main() {
	r := rand.New(rand.NewSource(1))
	var mflag uint64
	flag.Uint64Var(&mflag, "max", 0, "limit output to max bytes")
	flag.Parse()
	stdout := bufio.NewWriter(os.Stdout)
	if mflag != 0 {
		for i := uint64(0); i < mflag; i++ {
			if err := stdout.WriteByte(byte(r.Int())); err != nil {
				log.Fatal(err)
			}
		}
		stdout.Flush()
		return
	}

	for stdout.WriteByte(byte(r.Int())) == nil {
	}
}