Tinnu Posted June 16, 2010 Posted June 16, 2010 (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 June 16, 2010 by Tinnu
sahsanu Posted June 16, 2010 Posted June 16, 2010 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))
enaiman Posted June 16, 2010 Posted June 16, 2010 That's not the way to go; you can't get "random" groups in that way. What you need to do is: get random letter, get random number and then join them in a string. MsgBox(0, "Random string", Chr(Random(Asc("a"), Asc("z"), 1))&Random(1, 500, 1)) 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 :)
rbhkamal Posted June 16, 2010 Posted June 16, 2010 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
Tinnu Posted June 16, 2010 Author Posted June 16, 2010 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?
enaiman Posted June 16, 2010 Posted June 16, 2010 $sr value is constant it doesn't get re-calculated everytime. You need to put that "inside" the loop: While 1 Sleep(1000) MsgBox(0, "Random", Chr(Random(Asc("a"), Asc("z"), 1)) & Random(1,500,1)) WEnd 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 :)
Tinnu Posted June 16, 2010 Author Posted June 16, 2010 ok, thanks but now i am confused because i don't know which code will work faster and is better. can anyone tell?
enaiman Posted June 16, 2010 Posted June 16, 2010 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 ... 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 :)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now