Jump to content

Recommended Posts

Posted (edited)

hellos

i just tried this

msgbox(0, "Random", Chr(Random(Asc("a") & 1, Asc("z") & 300, 1)))
; the above code returns emty message box
; then tried this
msgbox(0, "Random", Chr(Random(Asc("a" & 1), Asc("z" & 200), 1)))
; but this gives only a-z not with numbers.

and it did not work.

i want results like

a1

b50

x9

t4

c251

Edited by Tinnu
Posted

i want results like

a1

b50

x9

t4

c251

Hello,

I don't really know what do you want but if you want a character between a and z (lower case) and a number between for example 1 and 500 then this could help you:

MsgBox(0,"Result",Chr(Random(Asc("a"), Asc("z"), 1)) & Random(1,500,1))
Posted

Func __GetRandomChars($p_sLen = 4)
    Local $L_sRand = ""
    
    For $l_ia = 0 To ($p_sLen -1)
        Switch( Random(0 , 1 , 1 ) )
            Case 1
                $L_sRand &= Chr(Random(Asc("a"), Asc("f"), 1))
            Case 0
                $L_sRand &= Random(0, 9, 1)
        EndSwitch
    Next
    
    Return $L_sRand
EndFunc

"When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix

Posted

ok, it's working fine.

but when i did this

$sr = Chr(Random(Asc("a"), Asc("z"), 1)) & Random(1,500,1)
While 1
    Sleep(1000)
    MsgBox(0, "Random", $sr)
WEnd

i am getting the same value again and again instead of changed one.

any solution to this?

Posted

ok, thanks

but now i am confused because i don't know which code will work faster and is better.

can anyone tell?

Posted

Your choice: your code giving always the same results is several miliseconds (maybe microseconds) faster than the one I posted which gives you the result you need.

I'm afraid it's up to you ... :mellow:

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...