From 6bb3690dde2b4939e43759db18165a28506787e2 Mon Sep 17 00:00:00 2001 From: shmansa Date: Tue, 21 Feb 2023 10:47:28 -0800 Subject: [PATCH 1/5] Added changes to files, fixes issue #1 and #2 --- .github/workflow/actions.yml | 20 ++++++++++++++++++++ GameDie.cpp | 2 +- main.cpp | 5 ++--- 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 .github/workflow/actions.yml diff --git a/.github/workflow/actions.yml b/.github/workflow/actions.yml new file mode 100644 index 0000000..0f4480f --- /dev/null +++ b/.github/workflow/actions.yml @@ -0,0 +1,20 @@ +name: Docker Image CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Build the Docker image + run: docker build -t cpp-container . + - name: Launch container + run: docker run -t cpp-container make diff --git a/GameDie.cpp b/GameDie.cpp index d8ecb3a..8dd274c 100644 --- a/GameDie.cpp +++ b/GameDie.cpp @@ -29,7 +29,7 @@ GameDie::GameDie(unsigned int num) { // generate a random number between 1-n where n is the counter size // (inclusive) and return it int GameDie::roll() { - int roll = rand_r() % roll_counter.size(); + int roll = rand() % roll_counter.size(); roll_counter[roll]++; return roll + 1; } diff --git a/main.cpp b/main.cpp index 65055f9..39efd65 100644 --- a/main.cpp +++ b/main.cpp @@ -7,7 +7,7 @@ using std::cout; using std::endl; int main(int argc, char *argv[]) { - if ( argc != 2 || std::atoi(argv[1]) < 1 ){ + if ( argc != 2 || std::atoi(argv[1]) < 1 ) { cout << "Incorrect command.\n" << "Format: ./Roller \n" << "--------------------\n" @@ -15,8 +15,7 @@ int main(int argc, char *argv[]) { << "--------------------\n" << " - Required; a number 1 or greater representing the number\n" << " of faces on the die being rolled\n"; - } - else { + } else { int faces = std::atoi(argv[1]); GameDie die(faces); cout << die.roll() << endl; From 91b10592844729f134572deeab3f142136295035 Mon Sep 17 00:00:00 2001 From: shmansa Date: Tue, 21 Feb 2023 11:43:06 -0800 Subject: [PATCH 2/5] added lint check #2 --- .github/workflow/actions.yml | 4 ++-- .github/workflow/cpplint.yml | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 .github/workflow/cpplint.yml diff --git a/.github/workflow/actions.yml b/.github/workflow/actions.yml index 0f4480f..6b70485 100644 --- a/.github/workflow/actions.yml +++ b/.github/workflow/actions.yml @@ -15,6 +15,6 @@ jobs: steps: - uses: actions/checkout@v3 - name: Build the Docker image - run: docker build -t cpp-container . + run: docker build -t roller . - name: Launch container - run: docker run -t cpp-container make + run: docker run -t roller make diff --git a/.github/workflow/cpplint.yml b/.github/workflow/cpplint.yml new file mode 100644 index 0000000..821f240 --- /dev/null +++ b/.github/workflow/cpplint.yml @@ -0,0 +1,20 @@ +name: Docker Image CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Build the Docker image + run: docker build -t roller . + - name: Launch container + run: docker run -t roller cpplint *.cpp *.h From 8a08c25938b082b388f833e8914ca3811a07b266 Mon Sep 17 00:00:00 2001 From: shmansa Date: Tue, 21 Feb 2023 11:55:57 -0800 Subject: [PATCH 3/5] added lint check #2 --- .github/{workflow => workflows}/actions.yml | 0 .github/{workflow => workflows}/cpplint.yml | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename .github/{workflow => workflows}/actions.yml (100%) rename .github/{workflow => workflows}/cpplint.yml (100%) diff --git a/.github/workflow/actions.yml b/.github/workflows/actions.yml similarity index 100% rename from .github/workflow/actions.yml rename to .github/workflows/actions.yml diff --git a/.github/workflow/cpplint.yml b/.github/workflows/cpplint.yml similarity index 100% rename from .github/workflow/cpplint.yml rename to .github/workflows/cpplint.yml From faee4ebe4e714313b8423b1121140b709f7dbd35 Mon Sep 17 00:00:00 2001 From: shmansa Date: Tue, 21 Feb 2023 12:04:12 -0800 Subject: [PATCH 4/5] added status badge #2 --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index d46f7c6..748f288 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ # Roller +[![Build Roller](https://github.com/shmansa/Roller/actions/workflows/actions.yml/badge.svg)](https://github.com/shmansa/Roller/actions/workflows/actions.yml) + +[![Lint Code Base](https://github.com/shmansa/Roller/actions/workflows/cpplint.yml/badge.svg)](https://github.com/shmansa/Roller/actions/workflows/cpplint.yml) + This repository provides a program that rolls a game die, such as the six-sided dice used in traditional dice game. From 6284556e154921e78b7405726a2efb7ffb802f45 Mon Sep 17 00:00:00 2001 From: shmansa Date: Tue, 21 Feb 2023 12:45:43 -0800 Subject: [PATCH 5/5] Added changes to files, fixes issue #1 and #2 --- .github/workflows/cpplint.yml | 2 +- GameDie.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cpplint.yml b/.github/workflows/cpplint.yml index 821f240..2773dd5 100644 --- a/.github/workflows/cpplint.yml +++ b/.github/workflows/cpplint.yml @@ -1,4 +1,4 @@ -name: Docker Image CI +name: Lint check on: push: diff --git a/GameDie.cpp b/GameDie.cpp index 8dd274c..dd20e38 100644 --- a/GameDie.cpp +++ b/GameDie.cpp @@ -29,7 +29,8 @@ GameDie::GameDie(unsigned int num) { // generate a random number between 1-n where n is the counter size // (inclusive) and return it int GameDie::roll() { - int roll = rand() % roll_counter.size(); + unsigned int seed = time(NULL); + int roll = rand_r(&seed) % roll_counter.size(); roll_counter[roll]++; return roll + 1; }