Forum

    • Register
    • Login
    • Search
    • Categories

    Easiest way to get a random float within a range?

    General Questions
    1
    3
    47
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • iamlamprey
      iamlamprey last edited by

      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?

      New Song 🥰 - Instruments

      1 Reply Last reply Reply Quote 0
      • iamlamprey
        iamlamprey last edited by

        Okay, found Engine.doubleToString 🙂

        New Song 🥰 - Instruments

        1 Reply Last reply Reply Quote 0
        • iamlamprey
          iamlamprey last edited by iamlamprey

          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

          New Song 🥰 - Instruments

          1 Reply Last reply Reply Quote 0
          • First post
            Last post

          3
          Online

          1.2k
          Users

          7.0k
          Topics

          64.8k
          Posts