Skip to content

Added Random::decision() which returns a bool based on a given probability - #70

Merged
Xrayez merged 1 commit into
goostengine:gd3from
mbrlabs:random-decide
Apr 29, 2021
Merged

Xrayez merged 1 commit into
goostengine:gd3from
mbrlabs:random-decide

Conversation

@mbrlabs

@mbrlabs mbrlabs commented Apr 29, 2021

Copy link
Copy Markdown
Contributor

I often use something like randf() < 0.33 to do something based on a given probability. This PR adds this functionality to Random. Not sure about the function name. It makes sense to me, but if you have a different suggestion i can change it of course.

@Xrayez Xrayez added feature 💡 New feature proposal topic:core labels Apr 29, 2021
@Xrayez Xrayez added this to the gd3 milestone Apr 29, 2021
@Xrayez

Xrayez commented Apr 29, 2021 •

Copy link
Copy Markdown
Contributor

Yeah makes sense I think. There's Random.condition read-only property which returns a random boolean in 50/50 cases, and is a noun. What about Random.decision(probability)? I mean, semantically it's not really the method which "decides" what has to be done, the decision is done by control paths such if statements. Compare:

if Random.decide(0.6):
    # Do something.

# vs

if Random.decision(0.6):
    # Do something.

On the other hand, the Random singleton is an object who "decides" as well.

Yet decide() is less verbose and easier to type, so I have no strong opinion on this. 🙂

@mbrlabs

mbrlabs commented Apr 29, 2021

Copy link
Copy Markdown
Contributor Author

Now that i see both versions side by side i have to agree that decision makes more sense. I changed it 👍

@Xrayez Xrayez changed the title Added Radom::decide() which returns a bool based on a given probability Added Radom::decision() which returns a bool based on a given probability Apr 29, 2021
@Xrayez

Xrayez commented Apr 29, 2021 •

Copy link
Copy Markdown
Contributor

I do think that this is useful, but after thinking about this more, it probably depends on the context.

As an active actor (say for NPCs), you'd certainly prefer to use "decision" word.

As a passive actor (chests with loot etc.), you'd probably be looking for something else. In this case, perhaps "chance(probability)" would be more appropriate.

So, I'm not suggesting to rename the method again, but the above sounds like two valid use cases to me. That said, I wouldn't be against adding additional "chance" method which would be basically an alias for the "decision" (or vice versa). However, if you think that "chance" is a better word to reasonably handle most use cases, then feel free to rename the existing method again. It's basically like having append and push_back for Array class, I'd just make this explicit in the documentation.

What do you think? I'd merge this in either case. 😮

@mbrlabs

mbrlabs commented Apr 29, 2021

Copy link
Copy Markdown
Contributor Author

I get what you mean, but aliases are in my opinion a bad idea. I already dislike this in Godot ( see append and push_back). How about something more generic and clear like evaluate_probability or eval_probability? It's a little bit more verbose but self-explanitory and it does not require any aliases.

@Xrayez

Xrayez commented Apr 29, 2021

Copy link
Copy Markdown
Contributor

Well, yeah, I think current name is fine as-is. Lets leave this to mean "the decision which is done by a program", rather than "decision which is done by an actor", this is probably just semantics.

@Xrayez

Xrayez commented Apr 29, 2021

Copy link
Copy Markdown
Contributor

Thanks and congrats for your first contribution!

@Xrayez
Xrayez merged commit c30d0eb into goostengine:gd3 Apr 29, 2021
@Xrayez Xrayez changed the title Added Radom::decision() which returns a bool based on a given probability Added Random::decision() which returns a bool based on a given probability Apr 29, 2021
@Xrayez Xrayez changed the title Added Random::decision() which returns a bool based on a given probability Added Random::decision() which returns a bool based on a given probability May 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature 💡 New feature proposal topic:core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants