random chars

So I am trying to make a little lua script so that you can input the amount of characters you want the password to be, then click generate and it will generate a new pass.

http://img207.imageshack.us/img207/340/rpgb.png

That is what I have so far I figured I could make a table

[lua]
local AllowedChars = {A, a, B, b, C, c, D, d, E, e, F, f, G, g, etc etc etc}[/lua]

Then use **[Table.Random

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Table.Random)** to get random chars but how can I make it so that it will input the certain amount of chars that is defined in the first textentry

With a delicate combination of a for loop and concatenation.

Could you explain a bit more



chars = {'a', 'b', 'c', 'd'};

function randomString(int len)
	string str = "";
	foreach(chars as $k => $v) do
		str = str + table.Random(chars);
	end
	return str;
end


Could but won’t.

This is really basic stuff and I’ve seen you around for quite a while, you should be able to solve this on your own.

Dim table As String

Alright
I think I can get it

[lua]
local AllowedChars = {A, a, B, b, C, c, D, d, E, e, F, f, G, g, etc etc etc}
[/lua]

You need to use strings maybe? And just use one of each case then do string.lower

I just did this…

[lua]

function string.random(length)
local str = “”;
for i = 1, length do
str = str…string.char(math.random(32, 126));
end;
return str;
end;
[/lua]

You can just modify the range of so you can exclude special chars and/or numbers.
I think its the easiest way to generate a random string when you don’t want to disallow specific chars.

Also Cubar, a bit butthurt today?

Why are you putting ; at the end of end

[editline]10th November 2010[/editline]

oh god

No idea.

It doesn’t matter anyway.

bad practice

[editline]10th November 2010[/editline]

and it looks G@Y

Cubar is just mad. Also, thanks for that snippet Wizard of Ass

Cubar’s mad, rating everyone dumb… lmao.

Actually it’s good practice because other more usefull languages require it. Unlike Visual Basic. And this is lua not VB.

You’ll get used to it soon.

it’s BAD PRACTICE.

I cant think of another language that even uses “end” let alone putting ; on them.

[editline]10th November 2010[/editline]

PHP:



function myfunc()
{
     echo("hi");
};


C++:



void myfunc()
{
       printf("hi");
};


C#:



private void myfunc()
{
        Console.WriteLine("hi");
};


Oh, I thought you were talking about the semi colons in general. Yeah that is weird.

I honestly don’t give a shit what you are telling me seth.

Also your pathetic attempts to be troll are making me sad.

-snip- not sure now…