Using Random.org to Generate Truly Random Numbers in .Net

Random numbers can be a pain if you have to generate new sequences each day. The normal ‘randomize()’ statement is seeded from the system timer so if you are running the generator at the same time, then there is a chance you will get the same sequence.

Over at   Random.org, Mads Haahr has been generating random numbers using atmospheric noise since 1998, and his method has the pseudo-random number generators build into VB.Net beat.

Here is the VB.Net wrapper to call random.org and get your numbers:


Imports System.Net

Public Class clsRandom
        Public Sub RandomizeReseed()
                Dim iSeed(0) As Integer

                iSeed = RandomIntegers(-1000000000, 1000000000, 1)
                Randomize(iSeed(0))
        End Sub

        Public Function RandomIntegers(ByVal MinValue As Integer, _
                ByVal MaxValue As Integer, _
                ByVal NumberCount As Integer) As Integer()

                Dim iC As Integer
                Dim iRetInts As Integer()
                Dim sRetIntsAsStr As String()
                Dim sURL As String

                If Math.Abs(MinValue) > 1000000000 Then
                        Dim ex As New Exception("MinValue cannot be greater than 1,000,000,000 or less than -1,000,000,000")
                        Throw ex
                End If

                If Math.Abs(MaxValue) > 1000000000 Then
                        Dim ex As New Exception("MaxValue cannot be greater than 1,000,000,000 or less than -1,000,000,000")
                        Throw ex
                End If

                If MinValue > MaxValue Then
                        Dim ex As New Exception("MinValue cannot be greater than MaxValue")
                        Throw ex
                End If

                If NumberCount > 10000 Then
                        Dim ex As New Exception("NumberCount cannot be greater than 10,000")
                        Throw ex
                End If

                sURL = "http://www.random.org/integers/?"
                sURL = sURL & "num=" & NumberCount
                sURL = sURL & "&min=" & MinValue
                sURL = sURL & "&max=" & MaxValue
                sURL = sURL & "&col=1&base=10&format=plain&rnd=new"

                sRetIntsAsStr = CallRandomDotOrg(sURL)
                ReDim iRetInts(sRetIntsAsStr.GetUpperBound(0))
                For iC = 0 To sRetIntsAsStr.GetUpperBound(0)
                        iRetInts(iC) = sRetIntsAsStr(iC)
                Next

                RandomIntegers = iRetInts
        End Function

        Private Function CallRandomDotOrg(ByVal sGetURL As String) As String()
                Dim objWebClient As New WebClient()

                Dim sResponse As String
                Dim sReturnInts() As String

                sResponse = objWebClient.DownloadString(sGetURL)
                If Right$(sResponse, 1) = vbLf Then
                        sResponse = Left$(sResponse, Len(sResponse) - 1)
                End If

                sReturnInts = sResponse.Split(vbLf)

                CallRandomDotOrg = sReturnInts
        End Function
End Class

Using the class is pretty simple. You can get an array of integers using the function:
RandomIntegers(MinValue, MaxValue, Count)

or you can seed the built-in random number generator with a truly random number by calling
RandomizeReseed()

This post brought to you by WeGotDomain.com - Over 10,000 Aged domains for sale!

Related posts:

  1. SEOMoz Linkscape API wrapper in VB.Net
  2. Getting Flights info from the Kayak API in ASP.Net
  3. Create a Website Comparison Widget using GoogleTrends

Using Google Trends for Websites to generate keywords

Google has just released Google Trends for Websites which allows you to compare traffic levels between sites - much like Alexa, comscore etc.

In itself, this is somewhat interesting, but what caught my eye was the ‘Also searched for’ results:

Here is a great way to get an idea which keywords are driving search engine traffic to your competitors.

So here is my idea

  1. Fire up google, and type the number one keyword that you can think of for your niche.
  2. Copy down the domains of the top 10 sites
  3. Go to Google Trends for Websites, enter the sites and copy down the ‘Also searched for’ keywords that come up. Make sure if you enter more than one site at a time that you change the ‘Ranked By’ so you get all the keywords.

So now you should have a pretty big list of keywords that are driving traffic to your niche :) I can’t be sure that the keywords listed are all the big ones, but I’ve compared the results with a hitwise report, and it is pretty close.

You can even figure out which keywords are the best to go after - just enter them into Google Trends

This post brought to you by WeGotDomain.com - Over 10,000 Aged domains for sale!

Related posts:

  1. My own Sudoku Google Gadget
  2. We Got Domain - over 10,000 aged domains for sale
  3. Using Google Translate to generate new content from old
  4. Quick Link Building tip
  5. Create a Website Comparison Widget using GoogleTrends