# Using Random

## Recommended Posts

I'm a bit confused with the Random function.

I looked over the help file and I get the basics, but I don't want numbers.

I've tried this.

```\$Ran = Random(10, 20)

Send(\$Ran)```

Then it gives a random number; in this case: 14.0981190651655

If I loop it, it keeps giving me the same number.

I'd like to make it so it displays random letters, how would I do that?

I'd also like it if it displays random letters, but not the same.

I'd like it to send the randoms so when it types it notepad it would type this, or something similar:

elekrjelkjlkrfjrlfkrjgwlkjd

dfjkrlgjrglkrgjrglkejtlkgjt

cedkjflrfjr54ltgkrjgtlkgjkj

Just whatever gibberish specified.

Help?

##### Share on other sites

Look over the help file some more. The example there shows how to get letters with the Function Random.

Edited by snowmaker

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

##### Share on other sites

The way to go about this, id to generate a random to number and assign it to a variable (\$i).

The variable then is used to represent an ascii decimal charactor number for a letter.

So the number will have to be withing the range of those letters you want to use.

Monkey's are, like, natures humans.

##### Share on other sites

I'm guessing this is what your trying to achieve.

```Local \$Alph = StringSplit ('ABCDEFGHIJKLMNOPQRSTUVWXYZ', ''); Puts the letters A-Z in to an array.
Local \$MaxChar = 10, \$Str = '', \$Last = ''; \$MaxChar = Max letters of gibberish.
For \$A = 1 To \$MaxChar; Start a for loop from 1 to \$MaxChar
Do
\$Ran = Random (1, \$Alph[0], 1); Produce a random number within range of the \$Alph array.
Sleep (15); Sleep 15 milli-seconds to insure 0% CPU usage.
Until \$Ran <> \$Last; Make sure the same number is not used twice.
\$Last = \$Ran; Set the current random number to \$Last so it is not used twice.
Sleep (15); Sleep 15 milli-seconds to insure 0% CPU usage.
\$Str = \$Str & \$Alph[\$Ran]; Update \$Str with the newest letter of gibberish.
Next
Send (\$Str); Set \$Str to notepad.```

Hope this helps!

- John

Latest Projects :- New & Improved TCP Chat

##### Share on other sites

To avoid repetitive results, use SRandom(@AutoitPID) before using Random(). Not completely foulproof, but better than no seed.

@John2010zz, Penisaurus

FYI, avoiding duplicate letters in a row gives a _less_ random output than when no such filtering is used.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

##### Share on other sites

I'm guessing this is what your trying to achieve.

```Local \$Alph = StringSplit ('ABCDEFGHIJKLMNOPQRSTUVWXYZ', '');
Local \$MaxChar = 10, \$Str = '', \$Last = ''; \$MaxChar = Max letters of gibberish.
For \$A = 1 To \$MaxChar; Start a for loop from 1 to \$MaxChar
Do
\$Ran = Random (1, \$Alph[0], 1); Produce a random number within range of the \$Alph array.
Sleep (15); Sleep 15 milli-seconds to insure 0% CPU usage.
Until \$Ran <> \$Last; Make sure the same number is not used twice.
\$Last = \$Ran; Set the current random number to \$Last so it is not used twice.
Sleep (15); Sleep 15 milli-seconds to insure 0% CPU usage.
\$Str = \$Str & \$Alph[\$Ran]; Update \$Str with the newest letter of gibberish.
Next
Send (\$Str); Set \$Str to notepad.```

Hope this helps!

- John

Pretty good one, use it all the time for Random session generation

Changed it a lil so you can choose the # of random characters to generate and return 10random characters if the \$MaxChar is left blank when called.

```Func _RandSession(\$MaxChar=10)

Local \$Alph = StringSplit ('ABCDEFabcdef123456789', ''); Use these characters in the returned random string (\$Str).

Local \$Str = '', \$Last = ''
For \$A = 1 To \$MaxChar; Start a for loop from 1 to \$MaxChar
Do
\$Ran = Random (1, \$Alph[0], 1); Produce a random number within range of the \$Alph array.
Sleep (15); Sleep 15 milli-seconds to insure 0% CPU usage.
Until \$Ran <> \$Last; Make sure the same number is not used twice.
\$Last = \$Ran; Set the current random number to \$Last so it is not used twice.
Sleep (15); Sleep 15 milli-seconds to insure 0% CPU usage.
\$Str = \$Str & \$Alph[\$Ran]; Update \$Str with the newest random character.
Next
Return \$Str
EndFunc```

Example:

```ConsoleWrite('Random Session using 4 = ' & _RandSession(4) & @CRLF);Returns 4 random characters
ConsoleWrite('Random Session using no input = ' & _RandSession() & @CRLF) ;Returns 10 Random Characters```
Edited by ALFJ

## Create an account

Register a new account

×

• Wiki

• Back

• Git