stanl
09-12-2007, 11:57 AM
Here is a fun sub you might want to throw into Excel and practice with. I like it, pretty fast [of course whaddya expect with 10 numbers :devil2: ] Stan
Sub randnums()
'just for testing, these can be passed as parms
'or located as cell values
nums = 10 ' number or results to return
nlow = -30000 ' minimum value
nhigh = 100000 ' max value
'use HTTP via the random.org website
'they advertise truly random numbers
cURL = "http://www.random.org/integers/"
cURL = cURL & "?num=" & nums & "&min=" & nlow & "&max=" & nhigh & "&col=1&base=10&format=plain&rnd=new"
Set oHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
oHTTP.Open "GET", cURL, False
oHTTP.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MyApp 1.0; Windows NT 5.1)"
oHTTP.Send
nStatus = oHTTP.Status
cResult = Trim(Replace(oHTTP.ResponseText, vbLf, ","))
If nStatus = 200 Then
' results stored as csv, could be parsed into cells
' and array... whatever
MsgBox "Random Number Results" & vbCrLf & cResult
Else
MsgBox "Error", "Status " & nStatus
End If
Set oHTTP = Nothing
End Sub
Sub randnums()
'just for testing, these can be passed as parms
'or located as cell values
nums = 10 ' number or results to return
nlow = -30000 ' minimum value
nhigh = 100000 ' max value
'use HTTP via the random.org website
'they advertise truly random numbers
cURL = "http://www.random.org/integers/"
cURL = cURL & "?num=" & nums & "&min=" & nlow & "&max=" & nhigh & "&col=1&base=10&format=plain&rnd=new"
Set oHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
oHTTP.Open "GET", cURL, False
oHTTP.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MyApp 1.0; Windows NT 5.1)"
oHTTP.Send
nStatus = oHTTP.Status
cResult = Trim(Replace(oHTTP.ResponseText, vbLf, ","))
If nStatus = 200 Then
' results stored as csv, could be parsed into cells
' and array... whatever
MsgBox "Random Number Results" & vbCrLf & cResult
Else
MsgBox "Error", "Status " & nStatus
End If
Set oHTTP = Nothing
End Sub