For a project, I need to make use of a random number generator to provide random numbers as part of a Fisher-Yates Shuffle. I am using both randomize() and randi()%1+50 methods to get my random numbers. However doing it this way does not let my Fisher-Yates shuffler count down to n=0, because if it does, it kicks out an error saying "Division By Zero in operator %" and points right at my generator range where the % resides. I can work around this by using rand_range(), however because rand_range() returns a float and not an integer, I am forced to round the result, which sometimes results in duplicate numbers, which I cannot have. ceil() and floor() are also out of the question for the same reason. This, of course, could all be solved if GDScript included something like "randi_range()" but I have seen on other forums that this has been a problem since 2014, and to which there still is no solution.
Given that this is not an option, does anyone know a way to return a random number, within a range, that does not include 0, that is a positive integer, that doesn't require the % operator to dictate the range?
Don't get me wrong, I love the Godot engine, and appreciate it for what it is, but sometimes the code requires a tad too much "wrestling" for my mental sanity to handle.
Any help would be greatly appreciated. Thanks in advance...
Aucun commentaire:
Enregistrer un commentaire