Easiest way to get a random float within a range?



  • Hey sorry for the potentially dumb question. I know Math.randInt() and Math.random() exist, but what's the best way to get a random float with say 2 decimal points within a range?

    So far I have

    randomFloat = Math.randInt(1, 8) - Math.range(Math.random(), 0.0, 0.7);
    

    Which works but how do I shave down the decimal points to something more end-user friendly?



  • Okay, found Engine.doubleToString 🙂



  • Okay now how do I convert the string back to a float so I can use it to control a module 😁

    Edit: ok adding another Math function to the string converts it back 🙂 easy


Log in to reply
 

10
Online

1.3k
Users

4.2k
Topics

38.3k
Posts