Forum

    • Register
    • Login
    • Search
    • Categories

    Math.randInt

    General Questions
    3
    10
    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.
    • MikeB
      MikeB last edited by

      Good morning all you developers of fascinating plug-ins -
      I haven't started yet and I'm still in a good mood 🙂

      I would like to have a problem, as we say here.

      I would like to use Math.randInt so that it only randomises between 2 values.
      One value is 0 and the other 99.
      So either 0 or 99.

      "One hour of trial and error can save 10 minutes of reading the manual."
      "It's easier to hit the developer with feature requests than to spend 10 minutes reading the manual. :-)))"
      HISE Develop - Mac Pro 5.1, OS X 10.14.6, Projucer 6.02, Xcode 10.3

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

        @MikeB something like

        var myValue = 0;
        var chance = Math.random();
        
        if (chance > .5) 
            myValue = 99;
        else
            myValue = 0;
        

        Music - Instruments

        MikeB 1 Reply Last reply Reply Quote 1
        • MikeB
          MikeB @iamlamprey last edited by

          @iamlamprey Thank you - you are the man of the morning. 🙂

          However, I need to transfer this to a slider pack.
          So I need two values or vars - right?

          SliderPack3.setSliderAtIndex(i, Math.randInt(0, 99));
          

          "One hour of trial and error can save 10 minutes of reading the manual."
          "It's easier to hit the developer with feature requests than to spend 10 minutes reading the manual. :-)))"
          HISE Develop - Mac Pro 5.1, OS X 10.14.6, Projucer 6.02, Xcode 10.3

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

            @MikeB If that's a for loop for each slider in the sliderpack, the code I posted above should still work.

            var chance; //use reg if it's during playback stuff
            
            for (i=0; i<sliderpacklength; i++) 
            {
                chance = Math.random();
                if (chance > .5)
                    SliderPack3.setSliderAtIndex(i, 99);
                else
                    SliderPack3.setSliderAtIndex(i, 0); 
            }
            

            Music - Instruments

            MikeB 1 Reply Last reply Reply Quote 2
            • MikeB
              MikeB @iamlamprey last edited by

              @iamlamprey
              Now you have become the man of the day 🙂

              Thank you very much.

              "One hour of trial and error can save 10 minutes of reading the manual."
              "It's easier to hit the developer with feature requests than to spend 10 minutes reading the manual. :-)))"
              HISE Develop - Mac Pro 5.1, OS X 10.14.6, Projucer 6.02, Xcode 10.3

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

                @MikeB Oh also if it's in a loop you can use local variables 🙂

                Music - Instruments

                MikeB 1 Reply Last reply Reply Quote 1
                • MikeB
                  MikeB @iamlamprey last edited by

                  @iamlamprey I have done this - thank you 👍

                  "One hour of trial and error can save 10 minutes of reading the manual."
                  "It's easier to hit the developer with feature requests than to spend 10 minutes reading the manual. :-)))"
                  HISE Develop - Mac Pro 5.1, OS X 10.14.6, Projucer 6.02, Xcode 10.3

                  1 Reply Last reply Reply Quote 0
                  • Christoph Hart
                    Christoph Hart last edited by

                    You can also do it like this:

                    Math.randInt(0, 2) * 99);
                    

                    (Note that the second argument is the exclusive limit of the range so for 0..1 you have to specify 2 as upper limit).

                    MikeB 1 Reply Last reply Reply Quote 2
                    • MikeB
                      MikeB @Christoph Hart last edited by

                      @Christoph-Hart
                      or so 🙂
                      I will try it out - thanks

                      "One hour of trial and error can save 10 minutes of reading the manual."
                      "It's easier to hit the developer with feature requests than to spend 10 minutes reading the manual. :-)))"
                      HISE Develop - Mac Pro 5.1, OS X 10.14.6, Projucer 6.02, Xcode 10.3

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

                        @Christoph-Hart It worked. Thank you.

                        Now all I need for a successful Sunday is an Arp Start/Stop button that works independently of Note On/Off.

                        Or a way to give a Note On/Off callback when a preset is called.

                        "One hour of trial and error can save 10 minutes of reading the manual."
                        "It's easier to hit the developer with feature requests than to spend 10 minutes reading the manual. :-)))"
                        HISE Develop - Mac Pro 5.1, OS X 10.14.6, Projucer 6.02, Xcode 10.3

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

                        7
                        Online

                        977
                        Users

                        6.6k
                        Topics

                        60.6k
                        Posts