HISE Logo Forum
    • Categories
    • Register
    • Login

    Math.randInt / Stop duplicate returns.

    Scheduled Pinned Locked Moved Solved Scripting
    3 Posts 2 Posters 193 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
      last edited by

      I have a randomizer button working. I notice that sometimes certain parameters dont change. Is that because Math.randInt is returning a duplicate number? Is there a formula to ensure that every integer returned is not the same as the last?

      Some of my groups have smaller numbers like 12 items so I suspect the Math is just returning duplicates sometimes.

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

        @Chazrox said in Math.randInt / Stop duplicate returns.:

        Math.randInt is returning a duplicate number?

        It's returning a random number, which might be the same as the previous number.

        The usual way to handle this is to store the generated value in a variable, then generate random numbers in a while loop until you get one that isn't the same as the previous value.

        It's also possible to do this without loops but the maths is a little more in depth. Here's an example of how to do it in Kontakt (KSP) for generating a non-repeating round robin - https://www.orangetreesamples.com/blog/scripting-nonrepeating-roundrobin

        And here's me demonstrating how to use the principles of that KSP script in HISE

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

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

          @d-healey Sweet! I'll watch this now. Hope you're having a great day brother! Thanks 🙏

          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
          • First post
            Last post

          24

          Online

          1.8k

          Users

          12.0k

          Topics

          104.4k

          Posts