HISE Logo Forum
    • Categories
    • Register
    • Login

    Random Integer from (-1.0 -> +1.0)

    Scheduled Pinned Locked Moved Solved Scripting
    25 Posts 4 Posters 2.6k 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.
    • ChazroxC
      Chazrox @d.healey
      last edited by

      @d-healey said in Random Integer from (-1.0 -> +1.0):

      Explanation:

      Math.random() generates a number in the range [0, 1].
      Multiplying by 2 scales it to [0, 2].
      Subtracting 1 shifts it to [-1, 1].

      Thanks for this. That really helps me understand the logic. I get it now. Im gonna watch the other video you gave me and put this together. Thanks again!

      1 Reply Last reply Reply Quote 0
      • ChazroxC Chazrox marked this topic as a question on
      • ChazroxC Chazrox has marked this topic as solved on
      • ChazroxC
        Chazrox @d.healey
        last edited by

        @d-healey I cant figure out what to change.

        Screenshot 2025-03-27 at 5.14.28 PM.png

        d.healeyD 1 Reply Last reply Reply Quote 0
        • d.healeyD
          d.healey @Chazrox
          last edited by

          @Chazrox That * doesn't look right, did you copy/paste it from somewhere or are you using a different font?

          This is how it looks for me

          00468a12-80ca-4bde-8eb5-e6dfce4b7915-image.png

          Libre Wave - Freedom respecting instruments and effects
          My Patreon - HISE tutorials
          YouTube Channel - Public HISE tutorials

          ChazroxC 2 Replies Last reply Reply Quote 0
          • ChazroxC
            Chazrox @d.healey
            last edited by

            @d-healey I typed it out myself. Its an " * " right?

            d.healeyD ustkU 2 Replies Last reply Reply Quote 0
            • ChazroxC
              Chazrox @d.healey
              last edited by

              @d-healey I didnt change my font either. Thats default font.

              1 Reply Last reply Reply Quote 0
              • d.healeyD
                d.healey @Chazrox
                last edited by

                @Chazrox What happens when you copy/paste those two lines to a new empty HISE file?

                Libre Wave - Freedom respecting instruments and effects
                My Patreon - HISE tutorials
                YouTube Channel - Public HISE tutorials

                ChazroxC 1 Reply Last reply Reply Quote 0
                • ustkU
                  ustk @Chazrox
                  last edited by

                  @Chazrox What do you have before line 7? sometimes an error ahead can appear later, for instance when a line of code isn't closed ;

                  Can't help pressing F5 in the forum...

                  1 Reply Last reply Reply Quote 0
                  • ChazroxC
                    Chazrox @d.healey
                    last edited by

                    @d-healey looks the same.
                    this is your code snippet copy/pasted.

                    Screenshot 2025-03-27 at 5.24.19 PM.png

                    d.healeyD ustkU 2 Replies Last reply Reply Quote 0
                    • d.healeyD
                      d.healey @Chazrox
                      last edited by

                      @Chazrox said in Random Integer from (-1.0 -> +1.0):

                      looks the same.

                      Yes, but does it work in the new project?

                      Libre Wave - Freedom respecting instruments and effects
                      My Patreon - HISE tutorials
                      YouTube Channel - Public HISE tutorials

                      1 Reply Last reply Reply Quote 0
                      • ustkU
                        ustk @Chazrox
                        last edited by

                        @Chazrox Screenshot 2025-03-28 at 01.25.31.png

                        Can't help pressing F5 in the forum...

                        ChazroxC 1 Reply Last reply Reply Quote 1
                        • ChazroxC
                          Chazrox @ustk
                          last edited by

                          @ustk I been changing each one to test but it wasnt working. Trying it in a new snippet per David rn. My lines are closed up above. Screenshot 2025-03-27 at 5.25.58 PM.png

                          ustkU d.healeyD 3 Replies Last reply Reply Quote 0
                          • ustkU
                            ustk @Chazrox
                            last edited by ustk

                            @Chazrox Since it's a namespace, maybe it's in the main script... The console is definitely saying something about a missing semicolon so... 🤷

                            Can't help pressing F5 in the forum...

                            1 Reply Last reply Reply Quote 0
                            • ustkU
                              ustk @Chazrox
                              last edited by ustk

                              @Chazrox And when you compile, is the focus on the script? meaning not "(detached)". This happens when you edit another script at the same time, so the modifications aren't compiled.
                              I find myself being tricked a lot by this everyday... "why the heck this isn't working... Oh ok... silly me..."

                              Screenshot 2025-03-28 at 01.34.16.png

                              Can't help pressing F5 in the forum...

                              ChazroxC 2 Replies Last reply Reply Quote 0
                              • d.healeyD
                                d.healey @Chazrox
                                last edited by

                                @Chazrox Don't use var for variables except when you have no other choice

                                Link Preview Image
                                HISE | Scripting | HiseScript Coding Standards

                                A collection of best practices for clean coding in HISE

                                favicon

                                (docs.hise.audio)

                                Libre Wave - Freedom respecting instruments and effects
                                My Patreon - HISE tutorials
                                YouTube Channel - Public HISE tutorials

                                ChazroxC 1 Reply Last reply Reply Quote 0
                                • ChazroxC
                                  Chazrox @ustk
                                  last edited by

                                  @d-healey @ustk

                                  I got it to work. I moved it to main script and it worked outside of the namespace. literlaly copy/pasted it out and it worked there. I put it back into the function and made randomFloat a local and it worked.

                                  Sometimes I dont even understand how things are fixed but they get fixed.

                                  ? 1 Reply Last reply Reply Quote 1
                                  • ChazroxC
                                    Chazrox @d.healey
                                    last edited by

                                    @d-healey sorry that pic was cut off. They're const vars for sure. I remember you teaching that in the tutorial. Screenshot 2025-03-27 at 5.44.33 PM.png

                                    1 Reply Last reply Reply Quote 1
                                    • ChazroxC
                                      Chazrox
                                      last edited by

                                      More than just helping me fix the problem. I always appreciate the logic! You guys are the best! 🙌

                                      1 Reply Last reply Reply Quote 0
                                      • ChazroxC
                                        Chazrox @ustk
                                        last edited by Chazrox

                                        @ustk said in Random Integer from (-1.0 -> +1.0):

                                        is the focus on the script?

                                        you mean am I compiling while on the main script?

                                        I havent seen that "detached' yet. My namespaces are local (external scripts) to the project. Would that apply to this situation?

                                        If im working within a namespace i'll usually do both for good measure...atleast I think thats good measure. lol.

                                        ustkU 1 Reply Last reply Reply Quote 0
                                        • ustkU
                                          ustk @Chazrox
                                          last edited by

                                          @Chazrox detached appears when you have more than one script in the module list. If you click in the module list to modify another script, or show its network for instance, this detaches the other scripts currently being edited. So if when you make a change, it's not compiled until you "re-attach" the script from the module's list and re-compile.

                                          detachedScript.gif

                                          Can't help pressing F5 in the forum...

                                          ChazroxC 2 Replies Last reply Reply Quote 1
                                          • ChazroxC
                                            Chazrox @ustk
                                            last edited by

                                            @ustk hmm...I never noticed that in my project yet. I'll keep that in mind. Sometimes a bunch of stuff will stop working and just start working again, I suspect thats whats happening but I just havent seen that message yet. Thanks!

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

                                            40

                                            Online

                                            1.8k

                                            Users

                                            12.1k

                                            Topics

                                            105.8k

                                            Posts