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

add: random element and weighted random element. #170

Merged
merged 2 commits into from
Apr 19, 2024

Conversation

arshamalh
Copy link
Contributor

Description

Currently, there are RandomStringElement and RandomIntElement methods in the package, but what happens if e.g. we want to select one of the users that are of type type User struct{...}, we may need a generic random select function and that's the reason I implemented RandomElement function.

Also, what happens if we want to give more chances to some elements? I added RandomElementWeighted for that purpose.

  • Added required test cases for previous functions and a test for RandomStringElement

Unfortunately, due to golang lack of support for typed parameters, these new two functions couldn't be methods and are implemented as functions taking Faker as argument (not receiver).


There was also a small change in time.ISO8601 function for how we format the time, as mentioned in this pkg

Are you trying to fix an existing issue?
No

Go Version

$ go version
go version go1.22.2 darwin/arm64

Go Tests
Runned on pipeline

$ go test
ok  	github.com/jaswdr/faker/v2	2.833s

@jaswdr jaswdr merged commit 4a84946 into jaswdr:master Apr 19, 2024
14 checks passed
@jaswdr
Copy link
Owner

jaswdr commented Apr 19, 2024

LGTM, thank you very much @arshamalh for your PR, I released your changes under v2.2.0

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

Successfully merging this pull request may close these issues.

2 participants