-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrandmif.go
42 lines (35 loc) · 978 Bytes
/
randmif.go
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
package main
import (
"flag"
"fmt"
"math/rand"
"time"
)
var (
depth = flag.Uint("d", 32, "depth")
width = flag.Uint("w", 4, "width")
)
func main() {
flag.Parse()
rand.Seed(time.Now().UnixNano())
fmt.Printf("-- Autogenerated MIF file with random values\n")
fmt.Printf("DEPTH = %2d; -- The size of memory in words\n", *depth)
fmt.Printf("WIDTH = %2d; -- The size of data in bits\n", *width)
fmt.Printf("ADDRESS_RADIX = HEX; -- The radix for address values\n")
fmt.Printf("DATA_RADIX = BIN; -- The radix for data values\n")
fmt.Printf("CONTENT -- start of (address : data pairs)\n")
fmt.Printf("BEGIN\n")
lg := log16(*depth)
for i := uint(0); i < *depth; i++ {
rn := rand.Intn(1 << *width)
fmt.Printf("%0*x : %0*b;\n", lg, i, *width, rn)
}
fmt.Printf("END;\n")
}
func log16(x uint) uint {
n := uint(0)
for i := uint(1); i < x; i <<= 4 {
n++
}
return n
}