Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

random string generator #39439

Closed
mostafasolati opened this issue Jun 6, 2020 · 3 comments
Closed

random string generator #39439

mostafasolati opened this issue Jun 6, 2020 · 3 comments

Comments

@mostafasolati
Copy link

@mostafasolati mostafasolati commented Jun 6, 2020

I think it would be nice if there is a random string generator in the standard library.
It can be in math/rand package.

@mvdan
Copy link
Member

@mvdan mvdan commented Jun 6, 2020

You can aready read random bytes: https://golang.org/pkg/math/rand/#Read

If that is not enough, you should clarify why. As far as I can see, as long as you can obtain any amount of random bytes, you can do anything from there.

@mvdan mvdan added the WaitingForInfo label Jun 6, 2020
@mostafasolati
Copy link
Author

@mostafasolati mostafasolati commented Jun 6, 2020

Thanks for your response. Yes, there is rand.Read but you don't have control over the output characters. Sometimes you need to generate a random string based on a given character set.
I think of something like this:
rand.String("AZXEgewdd1234$#!@*&")

@mvdan
Copy link
Member

@mvdan mvdan commented Jun 6, 2020

That's a higher level abstraction you could build on top of random bytes or integers. There's really no reason to put it in the package API. Different people will want different kinds of "random strings" too, so I also doubt that a single API would be universally useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.