Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Tag like string.random?

AnatolyAnatoly Mod
in Questions Posts: 830

is there any way that any type of tag will make any letter like string.random(8) will make different five letters or something like string.letter("a, b, c, d") will make only these letters. OffThisTopic: @Jmv38, why is everyone ignoring my topic "fun codes"?

Comments

  • dave1707dave1707 Mod
    Posts: 7,650

    @TokOut You can't make people read or comment on your discussions. As for string.random(), there isn't anything like that, but you can write your own function that does it.

  • dave1707dave1707 Mod
    Posts: 7,650

    @TokOut Here's a function that will return 2 strings of random letters. One is upper case and the other is lower case. Just change the value sent to stringRandom for different string lengths.

    function setup()
        print(stringRandom(8))
    end
    
    function stringRandom(x)
        local valU,valL="",""
        for _=1,x do
            valU=valU..string.char(math.random(string.byte("A"),string.byte("Z")))
            valL=valL..string.char(math.random(string.byte("a"),string.byte("z")))
        end
        return valU,valL
    end
    
  • dave1707dave1707 Mod
    Posts: 7,650

    @TokOut Here one that will give you 8 random letters from the letters you send to the function.

    function setup()
        print(stringLetter("qwertyuiop",8))    
    end
    
    
    function stringLetter(s,w)
        local str=""
        for _=1,w do
            v=math.random(1,s:len())
            str=str..string.sub(s,v,v)   
        end
        return str 
    end
    
  • AnatolyAnatoly Mod
    Posts: 830

    Thx

  • AnatolyAnatoly Mod
    Posts: 830

    @dave1707, can you do with this something like

    for x = string.byte("a"), string.byte("z") do
    .....
    

    And any way for this random strings, to use for a-z and the "_" symbol?

  • dave1707dave1707 Mod
    Posts: 7,650

    @TokOut You could use this. You could also add numbers or anything else you want to the list..

    function setup()
        print(stringLetter("abcdefghijklmnopqrstuvwxyz_",8))    
    end
    
    function stringLetter(s,w)
        local str=""
        for _=1,w do
            v=math.random(1,s:len())
            str=str..string.sub(s,v,v)   
        end
        return str 
    end
    
Sign In or Register to comment.