Home › Forums › General › Programming › randomize a text label?
- This topic has 36 replies, 3 voices, and was last updated 6 years, 5 months ago by human fly.
-
AuthorPosts
-
November 3, 2017 at 7:44 am #73388
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…)November 3, 2017 at 9:08 am #73389This 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.November 3, 2017 at 10:00 am #73391seems 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.November 3, 2017 at 12:47 pm #73392Yes 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 beforemath.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.November 3, 2017 at 2:27 pm #73394having 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.November 4, 2017 at 7:47 am #73395‘morning! ๐
ok, so i’ve studied v.1/2/3 of what you did yesterday,
and tweaked it a bit – see panel belowit 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.November 4, 2017 at 11:20 am #73397it 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.November 4, 2017 at 5:32 pm #73398had 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. …November 5, 2017 at 3:08 am #73405that the order of a method doesnโt matter too much,
because everything gets loaded before anything is runI think that is exactly correct;
November 5, 2017 at 11:38 am #73408“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.November 5, 2017 at 11:44 am #73409i 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???
November 5, 2017 at 12:23 pm #73410lol.. 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)
November 5, 2017 at 12:39 pm #73411Can you give a code example of that?
November 5, 2017 at 1:05 pm #73412November 5, 2017 at 1:31 pm #73418sorry! 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?November 5, 2017 at 1:42 pm #73419Oh 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, becauseasciiOkay()
is not global to the program.- This reply was modified 6 years, 5 months ago by dnaldoog.
November 5, 2017 at 1:58 pm #73421ok, 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. -
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.