jaevor / go-nanoid Goto Github PK
View Code? Open in Web Editor NEWNano ID for Go
Home Page: https://pkg.go.dev/github.com/jaevor/go-nanoid
License: GNU General Public License v3.0
Nano ID for Go
Home Page: https://pkg.go.dev/github.com/jaevor/go-nanoid
License: GNU General Public License v3.0
Notice the lack of numbers and lowercase letters in the below sample. Using go 1.22.2 and github.com/jaevor/go-nanoid v1.4.0
generator, err = nanoid.ASCII(32)
if err != nil {
panic(err)
}
for range 10 {
fmt.Println(generator())
}
Result:
IJ!YZQ#YI@}}~Q@},AJB~}AR+Q?RBIIB
?}!}R,~?YQ,I!R,IR,BA#A+~}A+AYQ@A
#~@!Y}IQ#JQ,QQBYBRQI}}#,QZZB}YB~
BI?J,Y+YI@~+Y#??Q@ZYY+Y?@#YJ}AR+
B+,A}Z@IQZZIA,!!#}!ZB?Y,I#Q}IA!!
}~RQBI@+AZ~@B}RB~?~,?}#R}AQ@B}AA
RQ}I+A#YAQB~Y?I}BI!~I!Q?,QI~??YY
@Q+}~!,R}~,RJ#+?+#@#IJJI~!J!Z@YA
?~!~!IQB~+YI~,I~#}!BZ+!?#JZ!YJ?,
#Y}!@~~R#YZ}Y,A!+}!JZ!RAQ?RQ+IJ+
It fails the below test that I added manually in my local environment.
func TestASCIIFlatDistribution(t *testing.T) {
tries := 500_000
length := 90
hits := make(map[rune]int)
f, err := nanoid.ASCII(length)
if err != nil {
panic(err)
}
for i := 0; i < tries; i++ {
id := f()
for _, r := range id {
hits[r]++
}
}
for _, count := range hits {
require.InEpsilon(t, length*tries/90, count, 0.01, "should have flat-distribution")
}
}
Can you comment on what major version of nanoid this library is based on? Their current library is at v4.
What are the advantages against matoous? Any benchmark improvement vs that library?
Some times I'm getting this panic on nanoid use.
github.com/jaevor/go-nanoid.ASCII.func1()
/Users/deferbot/go/pkg/mod/github.com/jaevor/[email protected]/nanoid.go:269 +0x1f0
I was wondering if it made sense to create a nanoid.StandardCanonical()
method (with no parameters) in order to avoid having to remember that 21
is the canonic length every time.
In other words, whoever wants a canonic generator could choose one between:
nanoid.Standard(21)
or
nanoid.StandardCanonic()
Would be nice to have MustCompile option like regex module.
Example with init()
var newNanoId func() string
func init() {
var err error
newNanoId, err = nanoid.CustomASCII("0123456789abcdefghijklmnopqrstuvxyz", 4)
if err != nil {
panic("nanoid: " + err.Error())
}
}
This would be nicer
var newNanoId = nanoid.MustCompileCustomASCII("0123456789abcdefghijklmnopqrstuvxyz", 4)
Reading this function I noticed you use sync,Mutex to lock a variable, however you are not using any go routine, so my question is about the purpose of this?
https://github.com/jaevor/go-nanoid/blob/master/nanoid.go#L84C9-L84C19
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.