Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Random Text Udf


  • Please log in to reply
9 replies to this topic

#1 ezzetabi

ezzetabi

    さくらが さいた

  • Active Members
  • PipPipPipPipPipPip
  • 2,011 posts

Posted 07 May 2004 - 02:25 PM

Nothing difficult... if ever need a password generator, a way to make temp file with out worry too much about files that already exists or what ever you can use this...

As usual, append to the end of file and call it :D
E.G.

;Creates the temp file for text operations
$TempFile = @TempDir & "\" & _RandomText(10) & ".tmp"
$TempFile = FileOpen($TempFile)


Func _RandomText($N)  ;$n is the lenght of string.    If $N < 1 Then Return -1    Local $COUNTER, $ALPHA, $RESULT        For $COUNTER = 1 To $N       If Random() < 0.5 Then          $ALPHA = Chr(Random(Asc("A"), Asc("Z") + 1))       Else          $ALPHA = Chr(Random(Asc("a"), Asc("z") + 1))       EndIf       $RESULT = $RESULT & $ALPHA    Next    Return $RESULT EndFunc  ;==>_RandomText








#2 Nutster

Nutster

    Developer at Large

  • Developers
  • 1,450 posts

Posted 07 May 2004 - 04:44 PM

Didn't I put something like this in the help file for Random?

David Nuttall

Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius
AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...


#3 emmanuel

emmanuel

    No one ever accused me of being normal.

  • Active Members
  • PipPipPipPipPipPip
  • 1,128 posts

Posted 07 May 2004 - 05:04 PM

well, it does seem to appear that the middle section of that code is in the help file, though a script-diot like me would not easily make the jump to what ezzetabi posted here...
"I'm not even supposed to be here today!" -Dante (Hicks)

#4 emmanuel

emmanuel

    No one ever accused me of being normal.

  • Active Members
  • PipPipPipPipPipPip
  • 1,128 posts

Posted 07 May 2004 - 06:06 PM

so, slap this in front of the random text code and you have a random password generator (though who would use these passwords?)
$char = InputBox("Random Password","How many characters?", "10") InputBox("Random Password","Here you go:", _RandomText($char))

"I'm not even supposed to be here today!" -Dante (Hicks)

#5 ezzetabi

ezzetabi

    さくらが さいた

  • Active Members
  • PipPipPipPipPipPip
  • 2,011 posts

Posted 10 May 2004 - 01:40 PM

Though who would use these passwords?

I always wondered too... Maybe people that sets email accounts for others?

#6 emmanuel

emmanuel

    No one ever accused me of being normal.

  • Active Members
  • PipPipPipPipPipPip
  • 1,128 posts

Posted 10 May 2004 - 03:37 PM

heh, yeah, I guess I could use them when a user forgets their password, it'd garuntee that they reset it to something else pdq
"I'm not even supposed to be here today!" -Dante (Hicks)

#7 ezzetabi

ezzetabi

    さくらが さいた

  • Active Members
  • PipPipPipPipPipPip
  • 2,011 posts

Posted 18 May 2004 - 05:22 PM

Since I actually found a useful use of it (random passwords), see encryption thread. I improved it :D
Now adds also numbers or write spaces.
The probability are calculated counting the number of characters.
total chars=63, 26 maiusc, 26 min, 10 digits, 1 space
10/63 = 15.87 % and so go on...

Func _RandomText($N)   ;$n is the lenght of string.    If $N < 1 Then Return -1    Local $COUNTER, $ALPHA, $RESULT, $RANDOM        For $COUNTER = 1 To $N       $RANDOM = Random()       Select          Case $RANDOM < .1587             $ALPHA = Chr(Random(Asc("0"), Asc("9") + 1))          Case $RANDOM < .5714             $ALPHA = Chr(Random(Asc("A"), Asc("Z") + 1))          Case $RANDOM < .9841             $ALPHA = Chr(Random(Asc("a"), Asc("z") + 1))          Case Else             $ALPHA = " "       EndSelect       $RESULT = $RESULT & $ALPHA    Next    Return $RESULT EndFunc  ;==>_RandomText


#8 piccaso

piccaso

    Rock me, Amadeus!

  • MVPs
  • 893 posts

Posted 18 May 2004 - 09:14 PM

I should check the forum more often, i jut wrote a similar function :huh2:

Func Uniqid()     Local $i, $rnd, $rval     For $i = 1 To 64   $rnd = Round(Random(1, 3), 0)   Select     Case $rnd == 1;uc (65-90)     $rval = $rval & Chr(Round(Random(65, 90), 0))     Case $rnd == 2;lc (97-112)     $rval = $rval & Chr(Round(Random(97, 112), 0))     Case $rnd == 3;nr (48-57)     $rval = $rval & Chr(Round(Random(48, 57), 0))   EndSelect     Next     Return $rval EndFunc  ;==>Uniqid


i think i'm going to benchmark them and see witch one is faster :D

Edit: And The winner is _RandomText witch generates about 33000 random strings more per hour :)

But why this +1 thing?

Edited by piccaso, 18 May 2004 - 09:53 PM.

Posted Image CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map

#9 ezzetabi

ezzetabi

    さくらが さいた

  • Active Members
  • PipPipPipPipPipPip
  • 2,011 posts

Posted 19 May 2004 - 06:46 AM

But why this +1 thing?

Just because Random($min,$max) do not include max in the results. So I have to keep $max one higher than the max number (that is Z, z or 9 char number)

Since you used Round(), you do not need this, all numbers greater than max - 0.5 will be rounded to max.
But I think is redundant force the computer round a number every time when the function already take Int(s) number and you can avoid the problem adding 1.

Edited by ezzetabi, 19 May 2004 - 06:49 AM.


#10 trids

trids

    Hmmm .. and what have we here?

  • Active Members
  • PipPipPipPipPipPip
  • 1,004 posts

Posted 19 May 2004 - 08:12 AM

though who would use these passwords?

Actually, random passwords like this are a very good idea :) .. And not only for clever file-trashing ..

There are commercial applications (and even freeware) that allow you to store your logins and passwords in a single database.

=> This means all you have to remember is a single password - the one for the database.

=> Which in turn means you can improve the strength of the passwords you store in it .. even to the point of making them obscure and difficult for anyone to remember: by using a password generator.

So you end up with good strong passwords (unique, mixed case, even including numerics and funny chars), without having to remember them. :huh2:

As I write this, I'm considering an AU3 applet to do just this, using the IDEA encryptor that ezzetabi posted to protect the database. Someone else might have the time and interest too :D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users