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 ability to pick random value from array #67444

Merged
merged 1 commit into from
Oct 21, 2022

Conversation

nonunknown
Copy link
Contributor

@nonunknown nonunknown commented Oct 15, 2022

Returns a random value from the target array.

var array: Array[int] = [1, 2, 3, 4]
print(array.pick_random())  # Prints either of the four numbers.

Implements: godotengine/godot-proposals#3454

@nonunknown nonunknown requested review from a team as code owners October 15, 2022 12:44
@kleonc kleonc added this to the 4.x milestone Oct 15, 2022
@kleonc
Copy link
Member

kleonc commented Oct 15, 2022

Alternative PR: #65077.

@jcostello
Copy link
Contributor

pick_random is an intuitive name, but just to let you know, other language or libraries call a similar method sample

@fire
Copy link
Member

fire commented Oct 16, 2022

Math::rand() is not the only way of getting a random number, by default Godot picks a not so random number generator.

Copy link
Member

@mhilbrunner mhilbrunner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved in #57007, and approved in today's PR meeting :)

@mhilbrunner
Copy link
Member

@nonunknown If you can update the docs to insert the new method's docs at the right place alphabetically, instead of the current place so CI passes, we can merge this. You can ping me once you updated it :)

@nonunknown
Copy link
Contributor Author

@mhilbrunner I have a serious problem with commit squashing, so if I can have support for squashing I can do this now!

@mhilbrunner
Copy link
Member

@nonunknown Sure, I can help you on RC or otherwise just squash the commits for you.

@nonunknown
Copy link
Contributor Author

I've checked #54940 and seems it doesnt interfere on this PR anymore, so this can be approved without worries!

@mhilbrunner mhilbrunner merged commit 5cefc07 into godotengine:master Oct 21, 2022
@mhilbrunner
Copy link
Member

Thanks! 🎉

@theraot
Copy link
Contributor

theraot commented Nov 4, 2022

May you bring this to 3.x?

@Overvault-64
Copy link

Is there any chance PackedStringArray and the others get pick_random() as well?
Don't know if it's intended but they don't inherit it from Array.

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

Successfully merging this pull request may close these issues.

9 participants