HISE Logo Forum
    • Categories
    • Register
    • Login

    Easiest way to get a random float within a range?

    Scheduled Pinned Locked Moved General Questions
    3 Posts 1 Posters 118 Views
    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.
    • ?
      A Former User
      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?

      1 Reply Last reply Reply Quote 0
      • ?
        A Former User
        last edited by

        Okay, found Engine.doubleToString :)

        1 Reply Last reply Reply Quote 0
        • ?
          A Former User
          last edited by A Former User

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

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

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

          15

          Online

          1.7k

          Users

          11.8k

          Topics

          102.4k

          Posts