this post was submitted on 20 Apr 2026
6 points (100.0% liked)

Godot

7849 readers
43 users here now

Welcome to the programming.dev Godot community!

This is a place where you can discuss about anything relating to the Godot game engine. Feel free to ask questions, post tutorials, show off your godot game, etc.

Make sure to follow the Godot CoC while chatting

We have a matrix room that can be used for chatting with other members of the community here

Links

Other Communities

Rules

We have a four strike system in this community where you get warned the first time you break a rule, then given a week ban, then given a year ban, then a permanent ban. Certain actions may bypass this and go straight to permanent ban if severe enough and done with malicious intent

Wormhole

!roguelikedev@programming.dev

Credits

founded 3 years ago
MODERATORS
 

There is a distinct lack of random functions for vectors, so I decided to add some to the Mouse Potato Utils Plugin.

However, I'm not sure whether I should make the right end of the range inclusive (make it a maximum) or exclusive (like the range() function) when it comes to integer vectors.

I'll make it inclusive for now, but what do you think?

top 5 comments
sorted by: hot top controversial new old
[–] gwheel@lemmy.zip 3 points 4 months ago (1 children)

I'm a fan of inclusive min, exclusive max for rng. It behaves consistently with decimal numbers in a readable way, for example int(0,100) can return 100 different integers. x<0 has a 0% chance of happening, x<50 is 50%, x<100 is 100%. If you swap with dec(0,100) you could now get 99.999 but x<50 is still exactly 50%

I do agree with amio on consistency and making sure each method added is worth the abstraction.

[–] MousePotatoDoesStuff@lemmy.world 1 points 4 months ago

In that case, I might add an optional boolean toggle for use as a range. But the default should be inclusive to stay consistent with the float method... I think.

[–] amio@lemmy.world 2 points 4 months ago (1 children)

Realistically, whichever one is the most commonly used in your project/framework/language/whatever, so it doesn't stick out as an inconsistency. If you're wondering about this now, it's a potential point of confusion for anyone who needs to read the code, including future you.

If you want to be really picky about engineering: are you sure you do need to write the function at all? How does the new function save time/effort or make code easier to read and write? Do you write a lot of code where you need random vectors, and does "random vector" mean the same thing in all cases? Would the function itself just make more code that needs maintaining, possibly indefinitely?

[–] MousePotatoDoesStuff@lemmy.world 1 points 4 months ago

I already named the variables minimum and maximum, so inclusive should make more sense. The code generates a vector within a square/cube defined by 2 other vectors.

Those are all good questions, and yes.

  • It saves time because I (and future plugin users) don't have to implement placing a vector in 2/3d space randomly, and it makes the code cleaner.
  • Not a lot, and yes.
  • The function is pretty much set-and-forget, but I might write an unit test just in case the laws of mathematics change overnight.
[–] FizzyOrange@programming.dev 1 points 4 months ago

What kind of vectors?

Without further information, right-open is usually the best choice.