PDA

View Full Version : Random Numbers via HTTP



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

malik641
09-12-2007, 05:14 PM
'use HTTP via the random.org website
'they advertise truly random numbers
There's no such thing as random. But I get the point.

That's some cool code, by the way. :) I'm sure I'll find a use for it.

stanl
09-13-2007, 06:10 AM
There's no such thing as random. But I get the point.


To be honest, I contacted the author after running thousands of iterations of my sample. I found that the probability of getting a 3 digit number in the range was ~ 1% and he said [more mathematically] 1.38% - that being the problem with other randon number generators - range consistency. Stan

YellowLabPro
09-13-2007, 02:58 PM
Malik,
I don't believe Harold Crick would agree. I think he would have to say Randomness totally exists.

but your's and my favorite-
http://askaninja.com/blades

malik641
09-13-2007, 03:05 PM
but your's and my favorite-
http://askaninja.com/blades
:rotlaugh:I love that one!

askaninja: Blade?
No glory.
askaninja: Glory?
No blades.

YellowLabPro
09-13-2007, 03:07 PM
I am guessing you had seen that one?

malik641
09-13-2007, 03:33 PM
I am guessing you had seen that one?
Yes :) Yes I have.