Nearly six years ago, Brian J gave up being a software developer to start a career in law enforcement. He specifically avoided the world of high-tech cyber crime, and wanted to start life anew as your everyday suburban cop. Of course, with a computer engineering degree and several years of IT experience, technology challenges tend to follow him wherever he goes.

For being a suburb, Brian’s department is pretty big and has a wide variety of posts that range from patrol to accident investigation. In addition, certain officers are trained to do certain things, and others have a preference... especially against the few horrible posts – such as manning the speed trap – that just suck the life out of most people for eight hours. As a result, shifts and schedules change from night to night.

A few years before Brian started, the department hired a consulting firm to develop software that would keep track of who was trained for what, who was on vacation, etc., and would then generate schedules based on that and the officers’ preferences. Recently, the sergeant had an idea for an improvement – add a supervisor preference to weigh certain officers higher for certain posts – and naturally turned to Brian for help.

Brian was pretty surprised to see the scheduling “software” was a massive spreadsheet. It was dressed up with buttons and colors, but it was nothing more than a massive Excel mess. Though it wasn’t exactly what he wanted to do as a police officer, he figured it’d be worth the brownie points, and if nothing else, get him off of speed trap duty.

As he dug through the spreadsheet, he noticed that the selection formula for the undesired posts used a function called superrand(). When he opened up the code view, he found his palm uncontrollably meeting his forehead.

' NOTE: random number functions don't produce true random numbers.
'       adding them together will improve the randomness by 
Function SuperRand() As Integer
    Dim iBadRandom As Integer
    Dim iGoodRandom As Integer
    
    Randomize
    
    ' Bad random should be total officers, good random should be total
    '  officers divided by 2

    iBadRandom = Int(46 * Rnd) + 1
    iGoodRandom = Int(23 * Rnd) + 1
    iGoodRandom = iGoodRandom + Int(23 * Rnd) + 1
        
    Do While iGoodRandom = iBadRandom
        iGoodRandom = Int(23 * Rnd) + 1
        iGoodRandom = iGoodRandom + Int(23 * Rnd) + 1
    Loop
    
    SuperRand = iGoodRandom
        
  End Function

Brian was able to hack-in the needed changes and, while he was in there, commented-out the superrand() function. He would have deleted it, but felt it was best to leave in place as a testament to a crafty bit of engineering.

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