| 30 | ) |
| 31 | |
| 32 | func New() *Random { |
| 33 | // https://tip.golang.org/doc/go1.19#:~:text=Read%20no%20longer%20buffers%20random%20data%20obtained%20from%20the%20operating%20system%20between%20calls |
| 34 | // sync.Pool must not be copied after first use; construct it directly |
| 35 | // on the struct to avoid copying from a local var. |
| 36 | return &Random{ |
| 37 | readerPool: sync.Pool{ |
| 38 | New: func() interface{} { |
| 39 | return bufio.NewReader(rand.Reader) |
| 40 | }, |
| 41 | }, |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | func (r *Random) String(length uint8, charsets ...string) string { |
| 46 | charset := strings.Join(charsets, "") |