randomize a text label?

Home Forums General Programming randomize a text label?

Viewing 17 posts - 21 through 37 (of 37 total)
  • Author
    Posts
  • #73388
    human fly
    Participant
      • Topics: 124
      • Replies: 1070
      • Total: 1194
      • โ˜…โ˜…โ˜…โ˜…

      hahaaa – that is the business ! you are quick, maaan ๐Ÿ™‚

      so there we have it: auto-gobbledegook generator.
      time to rename the panel.

      so: … (this one’s for later) is there a way to *exclude*
      unwanted ranges? hehehe

      (ie: unhelpful naming characters. i don’t really know if
      this is ever going to help anyone come up with new names
      for their patches – but i think the concept is valid for
      various uses. i used to ‘load’ randomizers, in a very
      simple way – for example for vcf envelope invert, where
      you don’t want it to return ‘inverted’ too often, stuff
      like that – a kind of ‘probability amount’ percentage.
      – similar to the way they hold referendums these days ! )
      (oops…)

      #73389
      dnaldoog
      Participant
        • Topics: 4
        • Replies: 480
        • Total: 484
        • โ˜…โ˜…

        This panel seems to do it, though not fully tested and seems a bit clunky. The strange looking lookup table:

        
        asciiOkay={
        [65]=65,  --A
        [66]=66,  --B
        [67]=67,  --C
        ....
        

        avoids having to loop through the table every time looking for characters to allow/include. There’s probably a much more elegant way of doing this.

        Attachments:
        You must be logged in to view attached files.
        #73391
        human fly
        Participant
          • Topics: 124
          • Replies: 1070
          • Total: 1194
          • โ˜…โ˜…โ˜…โ˜…

          seems to work pretty well – although every few clicks
          it doesn’t seem to change anything – ?
          had a quick look at method – !

          this is getting back to the array suggested by Proton, maybe.
          if math.random was addressing an array for this, it would be more
          direct?
          ok, time for real world out there… back later.

          #73392
          dnaldoog
          Participant
            • Topics: 4
            • Replies: 480
            • Total: 484
            • โ˜…โ˜…

            Yes I noticed that too if you click again too quickly. A delay of a second or two between clicks and it seems to work though.

            I read this:

            There is a know “issue” that the first call to math.random always returns the same value. You should do an extra call to math.random after you call math.randomseed and throw away the results.

            So in this panel I call that function twice with different parameters:

            
            randomSeeder =function(n)
            -- random seeder
            	--local t=os.time()
            	--local c=os.clock()
            	--math.randomseed(t*c)
            	math.randomseed(os.clock()*n)
            math.random(); math.random(); math.random() --warmup
            end --function
            ---------------------------------------------------------
            
            function createRandomName()
            -- create a random preset name
               randomSeeder(100000)
               randomSeeder(10000)
            	-- This variable stops index issues during panel bootup
            	if panel:getRestoreState() == true or panel:getProgramState() == true then return end
            
            -- --------------------------------------------------
            	tabl_NewName={}
            	strings={}
            	for i= 1,10 do
            	rnd=math.random(32,127) 
            	tabl_NewName=rnd
            console(String("random string = ["..rnd.."] = \""..myConvertToChar(rnd).."\""))
            if asciiOkay[rnd] ~= nil then
            table.insert(strings,myConvertToChar(rnd))
            end
            	end -- end loop
            console(String("_________________________________\n"))
            	DatasConcat = table.concat(tabl_NewName, " ")
            	if #strings > 0 and strings ~= nil then
            	stringsConcat=table.concat(strings)
            	else
            	stringsConcat="-------"
            	end
            	panel:getComponent("lcd_presetNameBis"):setPropertyString("uiLabelText",""..DatasConcat)
            	panel:getComponent("lcd_presetNameTer"):setPropertyString("uiLabelText",stringsConcat)
            strings=nil --clear previous table (Necessary???)
            
            end --function
            ---------------------------------------------------------
            

            If you only run the function …

            
               randomSeeder(100000)
               --randomSeeder(10000)
            

            …once, the results seem sameish .

            I also tried putting a sleep(500) function before math.randomseed(os.clock()) in that function randomSeeder() and that worked, but wondered if that was the best way to do it.

            ๐Ÿ™‚

            Attachments:
            You must be logged in to view attached files.
            #73394
            human fly
            Participant
              • Topics: 124
              • Replies: 1070
              • Total: 1194
              • โ˜…โ˜…โ˜…โ˜…

              having a few laughs with it anyway ๐Ÿ™‚
              already proving it can be useful.
              it rarely seems to come up with the long names, 8+
              characters – and you’ve done something to avoid
              spaces in the middle, yet it can produce names of
              shorter than 10 characters – have to look at it again
              more closely.

              evidently, one could spend a long time adding ‘rules’,
              favouring ..?who knows: consonant and vowel combinations,
              exclusions, lots of crazy stuff.

              #73395
              human fly
              Participant
                • Topics: 124
                • Replies: 1070
                • Total: 1194
                • โ˜…โ˜…โ˜…โ˜…

                ‘morning! ๐Ÿ™‚

                ok, so i’ve studied v.1/2/3 of what you did yesterday,
                and tweaked it a bit – see panel below

                it didn’t seem to need the new seeder, so it has that
                original time*clock (found in Possemo’s Matrix1000),
                and seem to trigger ok each time.

                couple of questions:
                why do you have this?
                console(String("_________________________________\n"))

                and

                else stringsConcat="-------"

                what does that do? it only has 7 ‘-‘s. is that an arbitrary
                display? (must be if it’s nil etc. ? – which it won’t be
                unless the method is triggered by other means, eg: popup menu,
                which you can escape from?)

                also, this (just an observation):
                console(String("random string = ["..rnd.."] = \""..myConvertToChar(rnd).."\""))

                i kept some notes as i got results doing ‘console’:

                --console(string.rep('-',i))	-- prints incrementally
                --console(String('-',i))	-- prints individually
                --console(String(presetName..i))-- appends a number to variable name
                --console(String("name"..i))	--creates a list of names with appended number

                and noted that the ‘” “‘ can be omitted in those concat expressions:

                --send it to preset name lcd
                	panel:getComponent("lcd_presetNameBis"):setPropertyString("uiLabelText",""..DatasConcat)
                	panel:getComponent("lcd_presetNameTer"):setPropertyString("uiLabelText",stringsConcat)

                (couldn’t figure out how you were displaying lower case until i realised
                you’d changed the font back to san-serif …Electronic doesn’t do lower case..)

                niiiice. ready to use ๐Ÿ™‚

                Attachments:
                You must be logged in to view attached files.
                #73397
                dnaldoog
                Participant
                  • Topics: 4
                  • Replies: 480
                  • Total: 484
                  • โ˜…โ˜…

                  it didnโ€™t seem to need the new seeder, so it has that
                  original time*clock (found in Possemoโ€™s Matrix1000),
                  and seem to trigger OK each time.

                  Yes it’s working for me now too – I was sure that code wasn’t working before ๐Ÿ˜ฎ

                  The console(String("_________________________________\n")) is just used for debugging, to print a line at the end of a loop, so I can delineate each loop.

                  I just threw that else stringsConcat="-------" in arbitrarily to print something if there are no Upper/Lower case hits.

                  console(String("random string = ["..rnd.."] = "\""..myConvertToChar(rnd).."\"")) is to show you can use ” in your console printout if you escape it with a backslash (in case you don’t know this already).

                  That string.rep() function is interesting. Didn’t know about that.

                  #73398
                  human fly
                  Participant
                    • Topics: 124
                    • Replies: 1070
                    • Total: 1194
                    • โ˜…โ˜…โ˜…โ˜…

                    had a feeling that String (etc.) was educational, thanks.
                    i have just the vaguest notion of escape slashes – probably a good time
                    to revise/revisit syntax pages. and go through your method a few times
                    more: naming and using variables as in that critical function at the end is
                    still nebulous and something i need to get into. i’ve been muddling along
                    without doing that. (mainly because the online tutorials need a bit of
                    translating, to be relevant to the Ctrlr newb’)

                    string.rep() > found whilst looking around for info.

                    seeing the way you construct methods, should i interpret this as
                    indicating that the order of a method doesn’t matter too much,
                    because everything gets loaded before anything is run? may seem
                    like a dumb question, but my instinct is to proceed in an order
                    that seems logical to me – evidently, if the critical function
                    comes in at the end, order doesn’t matter. – ? –

                    *however* your randomseeder() function appears before the
                    panel boot-up safeguard expression, which makes me think
                    it is being pre-seeded at boot-up. …

                    #73405
                    dnaldoog
                    Participant
                      • Topics: 4
                      • Replies: 480
                      • Total: 484
                      • โ˜…โ˜…

                      that the order of a method doesnโ€™t matter too much,
                      because everything gets loaded before anything is run

                      I think that is exactly correct;

                      #73408
                      human fly
                      Participant
                        • Topics: 124
                        • Replies: 1070
                        • Total: 1194
                        • โ˜…โ˜…โ˜…โ˜…

                        “Lua always precompiles source code to an intermediate form before running it”

                        going to digest the rest of that more slowly ๐Ÿ˜‰

                        i tried to make asciiOkay{} exist separately – but quickly ran into problems.
                        as i’ve seen arrays included separately- being picky, this would be a (very) minor
                        optimisation if you have to random more than one name. or i guess, if you wanted
                        to random from different arrays(?) with alternative options.

                        #73409
                        dnaldoog
                        Participant
                          • Topics: 4
                          • Replies: 480
                          • Total: 484
                          • โ˜…โ˜…

                          i tried to make asciiOkay{} exist separately โ€“ but quickly ran into problems.
                          as iโ€™ve seen arrays included separately- being picky, this would be a (very) minor
                          optimisation if you have to random more than one name. or i guess, if you wanted
                          to random from different arrays(?) with alternative options

                          ???

                          #73410
                          human fly
                          Participant
                            • Topics: 124
                            • Replies: 1070
                            • Total: 1194
                            • โ˜…โ˜…โ˜…โ˜…

                            lol.. sorry, bad post ๐Ÿ™‚ i’ve been getting to grips with a
                            volca sample that arrived through the post, big distraction.

                            i put that array into a separate method, to be called at
                            startup, but couldn’t immediately figure out how to refer to it
                            from within the main method.

                            if i put asciiOkay{} in a separate method called..? asciiValid()
                            what would replace:
                            if asciiOkay[rnd] ~= nil then .. etc.
                            ?

                            (completely unnecessary really – but could be useful)

                            #73411
                            dnaldoog
                            Participant
                              • Topics: 4
                              • Replies: 480
                              • Total: 484
                              • โ˜…โ˜…

                              Can you give a code example of that?

                              #73412
                              human fly
                              Participant
                                • Topics: 124
                                • Replies: 1070
                                • Total: 1194
                                • โ˜…โ˜…โ˜…โ˜…

                                (edit!)

                                • This reply was modified 6 years, 5 months ago by human fly.
                                • This reply was modified 6 years, 5 months ago by human fly.
                                • This reply was modified 6 years, 5 months ago by human fly.
                                • This reply was modified 6 years, 5 months ago by human fly.
                                #73418
                                human fly
                                Participant
                                  • Topics: 124
                                  • Replies: 1070
                                  • Total: 1194
                                  • โ˜…โ˜…โ˜…โ˜…

                                  sorry! terrible explanation.
                                  what i meant is: what it the asciiOkay{} was moved
                                  outside the main ‘createRandomName()’ method into
                                  its own method called at startup. how would createRandomName
                                  need to be changed?

                                  #73419
                                  dnaldoog
                                  Participant
                                    • Topics: 4
                                    • Replies: 480
                                    • Total: 484
                                    • โ˜…โ˜…

                                    Oh I see, well that table is already outside the method/function createRandomName() even though it’s in the same file.

                                    If you put it into its own function, then you would have to call it through a parameter to the function if it is declared ‘local’, otherwise you could still access the table from anywhere in the program if not declared ‘local’ even though it’s contained within the function.

                                    
                                    wrapTheTable=function(x)
                                    local asciiOkay={
                                    [65]=65,  --A
                                    [66]="I am on route 66",  --B
                                    [67]=67,  --C
                                    [68]=68,  --D
                                    [69]=69,  --E
                                    [70]=70,  --F
                                    [71]=71,  --G
                                    }
                                    return asciiOkay[x]
                                    end
                                    
                                    local var=wrapTheTable(66)
                                    console(String(var))

                                    will print “I am on route 66”

                                    If you run console(String(asciiOkay[66])) you should get an error, because asciiOkay() is not global to the program.

                                    • This reply was modified 6 years, 5 months ago by dnaldoog.
                                    #73421
                                    human fly
                                    Participant
                                      • Topics: 124
                                      • Replies: 1070
                                      • Total: 1194
                                      • โ˜…โ˜…โ˜…โ˜…

                                      ok, i see, thanks. i’ll give that a go.

                                      edit (later) – right, so i’ll abandon that idea:
                                      objective achieved anyway. thanks for all the help.
                                      useful little thing to have. originally wanted it
                                      for that panel that stores fake presets, because
                                      it was laborious putting in ‘names’ ๐Ÿ™‚ so it’s
                                      incorporated in that now, and in the proper panel
                                      i’m supposed to be making.

                                    Viewing 17 posts - 21 through 37 (of 37 total)
                                    • The forum ‘Programming’ is closed to new topics and replies.
                                    There is currently 0 users and 78 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