John B. saw some strange code that prompted him to investigate.

Dim rNumber As Integer = 0
rNumber = RandomNumber(13, 1)
Select Case rNumber
Case 0
Me.hl_logo.ImageUrl = "~/sysimages/header.jpg"
Case 1
Me.hl_logo.ImageUrl = "~/sysimages/header2.jpg"
Case 2
Me.hl_logo.ImageUrl = "~/sysimages/header.jpg"
Case 3
Me.hl_logo.ImageUrl = "~/sysimages/header.jpg"
Case 4
Me.hl_logo.ImageUrl = "~/sysimages/header2.jpg"
Case 5
Me.hl_logo.ImageUrl = "~/sysimages/header2.jpg"
Case 6
Me.hl_logo.ImageUrl = "~/sysimages/header.jpg"
Case 7
Me.hl_logo.ImageUrl = "~/sysimages/header.jpg"
Case 8
Me.hl_logo.ImageUrl = "~/sysimages/header2.jpg"
Case 9
Me.hl_logo.ImageUrl = "~/sysimages/header2.jpg"
Case 10
Me.hl_logo.ImageUrl = "~/sysimages/header.jpg"
Case 11
Me.hl_logo.ImageUrl = "~/sysimages/header2.jpg"
Case 12
Me.hl_logo.ImageUrl = "~/sysimages/header.jpg"
Case Else
Me.hl_logo.ImageUrl = "~/sysimages/header2.jpg"
End Select

He thought it was odd that the RandomNumber call looked so similar to the .NET Framework's built in Random.Next() function. Further down in the code file, he found this:

Public Function RandomNumber(ByVal MaxNumber As Integer, Optional ByVal MinNumber As Integer = 0) As Integer

'initialize random number generator
Dim r As New Random(System.DateTime.Now.Millisecond)

'if passed incorrect arguments, swap them
'can also throw exception or return 0

If MinNumber > MaxNumber Then
Dim t As Integer = MinNumber
MinNumber = MaxNumber
MaxNumber = t
End If

Return r.Next(MinNumber, MaxNumber)

End Function

John couldn't wrap his head around why it had been built this way, so he tracked down the original developer and asked.

"It makes it more random because you get more repeats when you select from two random numbers than you do with thirteen."

John must have missed the day in his stats class that explained why it's better to use 13 when there are only two possible outcomes.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!