Brittbot

Upgrading from Data Center Tech to Software Engineer

Logo for Click-Go-Lotto containing four lottery balls above the phrase.

Click-Go-Lotto: An Introduction

One of my technical projects I updated recently is Click-Go-Lotto (which you can visit here). In this post I will discuss the following topics about this web application:

  • Why I created it
  • The code running it
  • My future plans for the web application

Why I Created Click-Go-Lotto

My mom plays the Georgia lottery, both scratch-off tickets and lottery games like Mega Millions, Powerball, and Fantasy Five to name a few.

Like many lottery players she has her a set of favorite numbers to play for particular games over and over. However, there are times she allows the machine to randomly choose her numbers.

Instead of allowing the lottery machine to choose numbers for her, I decided to create a web app that could do the same. A benefit of a web app over a lottery machine is that she can generate as many random numbers as she wants without paying for them. My mom could use the app on her phone if she’s on the go, or on her laptop when she’s at home.

After brainstorming names for my app, I picked Click-Go-Lotto because users would click a button on the website to get the numbers. After coming up with the name I bought the domain name from Namecheap.

With the domain name in hand, it was time to design the web application. I already knew what tech stack I wanted to use: Bootstrap for the Front-End and Python/Flask for the Back-End.

The Code Running Click-Go-Lotto

All the code can be found on the project’s GitHub repo.

Front-End Code

I used Bootstrap to build out the Front-End of the website because of the following reasons:

  • Ease to use
  • Rich responsive website design features
  • Offers good performance

In addition to Bootstrap I use regular (or vanilla) HTML and CSS to build out the Front-End.

Back-End Code

I used Python and Flask to build out the Back-end of the website. I chose to use Flask over Django because it requires much less code to spin up a simple application.

The Python code to generate the random numbers is all in one module: games.py. I’ll include a snippet of that file below:

def cash3() -> tuple[int, int, int]:
    """This function provides the three numbers for the Cash 3 game.
    The game allows for numbers 0 to 9, and also allows for duplicate numbers.
    :return: Three individual random integers.
    """
    num1: int = random.randint(0, 9)
    num2: int = random.randint(0, 9)
    num3: int = random.randint(0, 9)
    return num1, num2, num3

...

def mega_millions() -> tuple[int, int, int, int, int, int]:
    """This function provides the six numbers for the Mega Millions game.
    The game allows for numbers 1 to 60, but doesn't allow for duplicate numbers except for the Mega Ball.
    :return: Six individual random integers.
    """
    num1: int = random.randint(1, 13)
    num2: int = random.randint(14, 26)
    num3: int = random.randint(27, 39)
    num4: int = random.randint(40, 52)
    num5: int = random.randint(53, 70)
    mega_ball: int = random.randint(1, 25)
    return num1, num2, num3, num4, num5, mega_ball

Let’s go through the code line by line:

  1. The function returns a tuple of Integers. The number of Integers range from three to six.
  2. Depending on the game, I either allow duplicate random numbers or use a range of random numbers to prevent duplicates.
  3. Each random number is assigned to a different variable.
  4. If the game has a specific lottery ball (like the Mega Ball in the previous code snippet) I assign a different random number to that variable.
  5. Finally, I return all the Integers from the function.
  6. The main.py file displays the numbers returned from the function:
@app.route("/games/cash3.html", methods=["GET", "POST"])
def cash3_game() -> render_template:
    """Displays the cash3.html template.
    :return: Cash 3 page displaying the three random numbers.
    """
    num1, num2, num3 = cash3()
    return render_template("/games/cash3.html", num1=num1, num2=num2, num3=num3)

...

@app.route("/games/mega-millions.html", methods=["GET", "POST"])
def mega_millions_game() -> render_template:
    """Displays the mega-millions.html template.
    :return: Mega Millions page displaying the six random numbers.
    """
    num1, num2, num3, num4, num5, mega = mega_millions()
    return render_template("/games/mega-millions.html", num1=num1, num2=num2, num3=num3, num4=num4, num5=num5,
                           mega=mega)

The main.py file contains all the routes (or links) to the specific game’s page. This is the Flask code hard at work!

I include the numbers on the game’s page template as so:

...

<div class="container game-container">
    <div class="row">
      <div class="col">
        <h1 class="game-title">Cash3</h1>
        <h2 class="lotto-num-short">{{ num1 }} - {{ num2 }} - {{ num3 }}</h2>
        <form action="cash3.html" method="post">
          <button class="btn btn-lg game-btn" name="regenerate" type="submit"
            onclick="{{ num1 }} {{ num2 }} {{ num3 }}">Click-Go-Lotto Again</button>
        </form>
      </div>
    </div>
  </div>

...

If users wants to generate a new set of numbers they click the button on screen, which runs the specific function again.

My Future Plans For This Application

I don’t have any major plans to modify the code for Click-Go-Lotto. It’s pretty much complete, unless a lottery game changes.