Generation a random number in Golang can be done via 2 packages -
math/rand and
crypto/rand. We have explored the math/rand
way in this post where we have to set the seed every-time when we want to generate the number and that might cause issue when you are generating a lot of numbers in given time. Due to seed settings, there are chances that you will get a duplicate random number hence Golang provides an another package crypto/rand to deal with this dilemma.
Today's post is simply a crypto/rand implementation to generate random string.
--
Output:
❯ go run 38-random-string-simplified.go
Random Number 1: zo38MaNsjIOtEtwNYge0NHQfwpSwPmym
Random Number 2: SYreojBSaHdRCYo2bbDcff8HR7_zbncZ
Random Number 3: 55tQB_WRe1SMDqM0EypNM9ZwHF-cfsbZ
Random Number 4: 8?e3oQP4MRlfDEga6x8SOF_o7QbA6pSW
Random Number 5: w3rQuQVU7KxUGFYRn8pv?Z98L??7UBLv
Like the below page to get the update
Facebook Page
Facebook Group
Twitter Feed
Telegram Group
No comments:
Post a Comment