mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Apr 2003
Posts: 426
N
Fjord artisan
OP Offline
Fjord artisan
N
Joined: Apr 2003
Posts: 426
$rand is really cool, however, it lacks that additional something...

That something is the ability to create a random string of x width. Hence the idea of $randstr(l,x,y).

An explanation:

l - The length of the string.
x - The start point for the characters (can be alpha or number).
y - The end point for the characters (can be alpha or number).

Example:
$randstr(15,a,z)
Output: aksuiejfkanlkwp


$randstr(l,x,y) would work exactly like $rand works.


Yes, I could script this... But meh.

D
DaveC
DaveC
D
nice idea i like it, but rather than just char i would have it just repo the random result n times (with a space between option maybe)

heres a short script to do it (yeah i know you said you could already do that)

alias randstr return $($str($chr(32) $+ $!rand($$2,$$3) $!+,$$1),2)

O
Om3n
Om3n
O
Currently $rand will only return a random number/letter within the range you specify, with the format $rand(START,END)

What i would like to see it be able to do is return a random CHARACTOR from a specified STRING of charactors. Therefor not limiting it to JUST letters or JUST numbers, and also not limiting it to a SINGLE specific range.

Possibly :: $rand(chrset, N) where N is the number of random charactors you want and chrset is the charactor set. eg. $rand(abcxyz1289, 4) would return 4 random charactors from the charactor set 'abcxyz1289'.

Other format possibilities that come to mind would be $rand(r1[|r2|r?...], N) where N is the number of random charactors you want (1 if not specified) and r1|r2 etc are the ranges that the charactor will be taken from. Ranges could be entered in as string (abcd) or as a range (a-z/1-999...)
eg1 $rand(ad|m-t|z1|6-9, 3) - would return 3 random charactors from the range 'admnopqrstz16789'
eg2 $rand(a-d) - would work as rand does now and return 1 charactor from the range 'abcd'

Infact after reading that back to myself i much prefer the second Syntax and would also function correctly to do what neophyte is asking.

S
saxon
saxon
S
I dont know, My personal thought is that this should be scripted. It's a very specialised need... Mirc provides you the means to do it easily... Despite the fact that it's easy to script, I dont really think it would be a meaningful or nice addition either... Just my opiinion.

Joined: Dec 2002
Posts: 1,893
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,893
When I need a unique string I use $ticks... With $rand there is always the chance of falling twice on the same result wink

O
Om3n
Om3n
O
The gist of my post was that i think $rand should be able to do both number and latters, not one or the other, perhaps v1 and v2 could be ascii numbers, so that a whole charactor set can be used? The other stuff i guess is probably better scripted.

Joined: Apr 2003
Posts: 426
N
Fjord artisan
OP Offline
Fjord artisan
N
Joined: Apr 2003
Posts: 426
alias randstr {
var %len = $$1
while (%len > 0) {
var %str %str $rand($$2,$$3)
dec %len
}
return $remove(%str,$chr(32))
}

Works just as well too.

D
DaveC
DaveC
D
Yours Is actually a lot better, the one i did, can be broken quite quickly with large length requests, as it translates to a string of " $rand($2,$3) $+ " repeating $1 times and ends up blowing the line length, but i thought it looked quite clever, when i saw it in someone elses random string generator, so i thought id post here.


Link Copied to Clipboard