Jump to content

how to get random value?


Recommended Posts

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
Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

$sr value is constant :mellow: 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 :)

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...