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.


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

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);
	return str;

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

I think I can get it

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

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

I just did this…


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

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.


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

[editline]10th November 2010[/editline]


function myfunc()


void myfunc()


private void myfunc()

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…