My scrapbook about anything which I learned or want to remember, Sometime about tech tips, thoughts and rambling. If you find anything useful don't forget to give thumbs-up :)

Breaking

Monday, October 3, 2022

Random Number Genearion with crypto/rand - Golang

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

Disclaimer

The postings on this site are my own and don't necessarily represent IBM's or other companies positions, strategies or opinions. All content provided on this blog is for informational purposes and knowledge sharing only.
The owner of this blog makes no representations as to the accuracy or completeness of any information on this site or found by following any link on this site. The owner will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of his information.