Consulting

Results 1 to 7 of 7

Thread: Random Numbers via HTTP

  1. #1
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location

    Random Numbers via HTTP

    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 ] Stan

    [vba]
    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

    [/vba]

  2. #2
    Administrator
    2nd VP-Knowledge Base
    VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Quote Originally Posted by stanl
    [vba]'use HTTP via the random.org website
    'they advertise truly random numbers[/vba]
    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.




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  3. #3
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Quote Originally Posted by malik641
    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

  4. #4
    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
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  5. #5
    Administrator
    2nd VP-Knowledge Base VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Quote Originally Posted by YellowLabPro
    but your's and my favorite-
    http://askaninja.com/blades
    I love that one!
    askaninja: Blade?
    No glory.
    askaninja: Glory?
    No blades.




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  6. #6
    I am guessing you had seen that one?
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  7. #7
    Administrator
    2nd VP-Knowledge Base VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Quote Originally Posted by YellowLabPro
    I am guessing you had seen that one?
    Yes Yes I have.




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •