Should Raylib provide a function to generate random floats or doubles? #4636
Replies: 5 comments 2 replies
-
What exactly would be the API for a random double generator, including initiation and establishing boundaries? As a curiosity, what is an example of such usage in game development? |
Beta Was this translation helpful? Give feedback.
-
@barodapride I think it can be managed on user side with the already provided functions. |
Beta Was this translation helpful? Give feedback.
-
It can be managed on the user side but why not provide it out of the box? Here's what I'm doing. ` // Returns a random float between 0 and 1.0f (inclusive) // Returns a random float between min and max (inclusive) This generates a random float using the seed from Raylib since it's derived from GetRandomValue. You could say the 'resolution' of the float is limited by INT_MAX but practically speaking would anybody care about that? I would guess the vast majority of Raylib users would just use the Raylib provided function instead of implementing something different but I'm open to reasons why this would not be a good idea. |
Beta Was this translation helpful? Give feedback.
-
Because it adds a maintenance cost to raylib that I prefer to avoid. |
Beta Was this translation helpful? Give feedback.
-
Any time you need a random angle. Angles are distributed from 0 to 2π, which you cannot easily translate to integers without sacrificing uniformity. The case that led me here needs a unit vector in a uniformly-distributed random direction to apply random movement. Random fractions between 0 and 1 are also common, e.g. a 70% chance succeeds when randomFloat(0, 1) < 0.7. This latter case is common enough that many float-based RNG methods are based on or even only provide a random number from 0 to 1 and expect the user to transform it to an applicable range. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I'm just wondering why Raylib provides a method to get a random int but doesn't provide something similar for random floats or doubles.
I understand it might be easier to provide a random int based on a seed value but if there was a pull request for a random float generator that was solidly implemented would it get rejected? Providing a way to get random floats and doubles seems within the scope of Raylib given that it's so common in game development and Raylib already provides a way to generate random ints.
Beta Was this translation helpful? Give feedback.
All reactions