nice random

Home Forums General Programming nice random

Tagged: 

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #82753
    human fly
    Participant
      • Topics: 124
      • Replies: 1070
      • Total: 1194
      • ★★★★

      thought i’d share this little script for randomizing
      a list of parameters with different values ranges.
      (the seeder is by Possemo, and the min/max property
      was from something by dnaldoog)

      function randVoice()
      -- This variable stops index issues during panel bootup
      if panel:getRestoreState() == true or panel:getProgramState() == true then return end
      -- -----------------------------------------------------
      	local t=os.time()	--[random seeder]--
      	local c=os.clock()
      	math.randomseed(t*c)
      -- -----------------------------------------------------
      	local param=nil 
      	local min=nil
      	local max=nil
      	local rnd=nil
      
      	for i=1,21 do 
      	param=tbl_voiceParam	--[Voice Edit params]--
      	--[any value range]--
      	min = param:getProperty("modulatorMin")
      	max = param:getProperty("modulatorMax")
      	rnd=math.random(min,max)
      	param:setModulatorValue(rnd,false,false,false)
      	end
      end

      i also tried to shorten it, but for some reason, the following
      does not seem to work (bad argument):

      --	for i=1,21 do 
      --	--[any value range]--
      --	tbl_voiceParam:getProperty("modulatorMin")
      --	tbl_voiceParam:getProperty("modulatorMax")
      --	rnd=math.random(min,max)
      --	tbl_voiceParam:setModulatorValue(rnd,false,false,false)
      --	end
      --end
      #82755
      Possemo
      Participant
        • Topics: 14
        • Replies: 638
        • Total: 652
        • ★★★

        There is a better randomseed:
        math.randomseed(Time.getMillisecondCounterHiRes())
        The other one does not work correctly when using 32-Bit Ctrlr.

        You aren’t using i anywhare in your loop. This will set the same parameter 21 times?

        #82784
        human fly
        Participant
          • Topics: 124
          • Replies: 1070
          • Total: 1194
          • ★★★★

          ok, i’ll check out your new seeder if you say the other
          one has problems – working great here with 64bit.

          sorry, that’s the forum omitting square brackets without
          the space, i thought that was fixed because it appeared
          ok when i posted. should read:

          	for i=1,21 do 
          	param=tbl_voiceParam[ i ]	--[ Voice Edit params ]--
          	--[ any value range ]--
          	min = param:getProperty("modulatorMin")
          	max = param:getProperty("modulatorMax")
          	rnd=math.random(min,max)
          	param:setModulatorValue(rnd,false,false,false)
          	end

          hope it reads better now.

          #82785
          human fly
          Participant
            • Topics: 124
            • Replies: 1070
            • Total: 1194
            • ★★★★

            so this should also be:

            --	for i=1,21 do 
            --	--[any value range]--
            --	tbl_voiceParam[ i ]:getProperty("modulatorMin")
            --	tbl_voiceParam[ i ]:getProperty("modulatorMax")
            --	rnd=math.random(min,max)
            --	tbl_voiceParam[ i ]:setModulatorValue(rnd,false,false,false)
            --	end
            --end

            i tried (tbl_voiceParam[ i ]) ,regular brackets, as well, and figure
            it ought to work (?) so i don’t know how to do that. it’s just to skip
            a stage, thought it would do that.

            #82786
            Possemo
            Participant
              • Topics: 14
              • Replies: 638
              • Total: 652
              • ★★★

              Ah ok. I have seen this too. In some cases you have to put it in a variable first.

              #82826
              human fly
              Participant
                • Topics: 124
                • Replies: 1070
                • Total: 1194
                • ★★★★

                confirming that your new seeder is working fine.
                thanks! (hope it isn’t producing pseudo-random?
                s’pose not, if it depends on system clock)

                i like your comment ‘in some cases’ LOL
                would you like to elaborate?
                (‘coz i’ve found some other interesting ‘in some
                cases’ with some other stuff. i’ll have to get
                together a post for those – found workarounds though.
                like: you do *exactly the same thing, in the same context*
                and in one case it works, but not in the second… wdf…)

                #82830
                Possemo
                Participant
                  • Topics: 14
                  • Replies: 638
                  • Total: 652
                  • ★★★

                  The newer seed uses a high resolution time counter. I guess it will produce a small number with many decimal points. This seems to work better on 32-Bit app than a big number randomseed. On x64 it doesn’t seem to make a difference. I saw the hires counter on a demo panel from atom. You can learn a lot when you check all demo panels carefully.

                  “in some cases”: I would say you have to use “interim” variables in some cases when you are accessing modulators such as panel:getModulatorByName etc.

                  #82831
                  human fly
                  Participant
                    • Topics: 124
                    • Replies: 1070
                    • Total: 1194
                    • ★★★★

                    interim variable, makes sense.
                    (think i figured out why the other thing wasn’t working)

                    #82839
                    human fly
                    Participant
                      • Topics: 124
                      • Replies: 1070
                      • Total: 1194
                      • ★★★★

                      ah: discovered something interesting…(change of topic, really,
                      this should be over on RX7 topic) …
                      i am checking my data reference lists with ‘print jobs’,
                      because i have to match 1,100 lists to 1,128 lists, for the
                      purpose of assigning voice numbers to midi note numbers.

                      i’m printing stuff out in a format that i can copy and paste
                      from the console into a table directly.

                      so i’ve discovered that i cannot have """ because it just
                      leaves the apostrophes open, …of course. i need to do this
                      because i’m displaying numbers concatenated with text, and
                      then concatenate a comma in apostrophes, so it’s ready to
                      just paste where i want it.

                      although it is not ‘recommended to mix " and ', i found
                      that i can do it for this purpose and get the result wanted.

                      ie: " ' "

                      anyway: that’s it for the random topic. i’m over on the RX7
                      thing now. 😉

                      • This reply was modified 6 years, 1 month ago by human fly. Reason: amended
                    Viewing 9 posts - 1 through 9 (of 9 total)
                    • The forum ‘Programming’ is closed to new topics and replies.
                    There is currently 0 users and 73 guests online
                    No users are currently active
                    Forum Statistics
                    Threads: 2,495, Posts: 17,374, Members: 77,605
                    Most users ever online was 12 on January 22, 2019 3:47 pm
                    Ctrlr