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
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@mostafasolati
Copy link
Contributor

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 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 Issue is not actionable because of missing required information, which needs to be provided. label Jun 6, 2020
@mostafasolati
Copy link
Contributor Author

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 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.

@golang golang locked and limited conversation to collaborators Jun 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants