jmcvetta / randutil Goto Github PK
View Code? Open in Web Editor NEWRandom number/string utility library for Go
License: GNU General Public License v3.0
Random number/string utility library for Go
License: GNU General Public License v3.0
2bb1b66 does not pass Go 1.10 unit tests
+ GOPATH=/builddir/build/BUILD/randutil-2bb1b664bcff821e02b2a0644cd29c7e824d54f8/_build:/usr/share/gocode
+ go test -buildmode pie -compiler gc -ldflags '-extldflags '\''-Wl,-z,relro '\'''
# github.com/jmcvetta/randutil
./randutil_test.go:56: Sprintf call has arguments but no formatting directives
FAIL github.com/jmcvetta/randutil [build failed]
I wanted to test for any biases the string generator might have; sadly, it looks like the generator is strongly biased against the last character in a set - it never gets picked.
I wrote this test program:
package main
import (
"os"
"strconv"
"fmt"
"github.com/jmcvetta/randutil"
)
const (
PasswordCharacters = "}~"
)
func main() {
howmany, err := strconv.Atoi(os.Args[1])
if err != nil {
fmt.Printf("Need a password length, error %s\n", err)
os.Exit(1)
}
length, err := strconv.Atoi(os.Args[2])
if err != nil {
fmt.Printf("Need a password count, error %s\n", err)
os.Exit(1)
}
charWeights := make(map[rune]int)
for _, c := range PasswordCharacters {
charWeights[c] = 0
}
for i := 0; i < howmany; i++ {
onePass, err := randutil.String(length, PasswordCharacters)
if err != nil {
fmt.Printf("Got error generating pass: %v\n", err)
}
for _, c := range onePass {
charWeights[c]++
}
}
for _, c := range PasswordCharacters {
count := charWeights[c]
fmt.Printf("%d\t%c\n", count, c)
}
}
Then I ran this:
go run ./main.go 45 200
and get this result:
9000 }
0 ~
-- Expanding the character set, it looks like it's selecting every character but the last one.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.