-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add random number generator script + GitHub Actions workflow
- Loading branch information
0 parents
commit 420069a
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: update | ||
|
||
on: | ||
schedule: | ||
# Run daily at 04:20 UTC. | ||
- cron: '20 4 * * *' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
update: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: ${{ github.head_ref }} | ||
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | ||
- name: Update | ||
run: | | ||
./update.sh | ||
git config user.name 'TibiaMaps.io lottery bot' | ||
git config user.email 'lottery@tibiamaps.io' | ||
date=$(date +'%Y-%m-%d') | ||
git add data | ||
git commit data -m "Add random numbers for date=${date}" || true | ||
git push |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
from secrets import randbelow | ||
|
||
# Print to stderr. | ||
def eprint(*args, **kwargs): | ||
print(*args, file=sys.stderr, **kwargs) | ||
|
||
# Generate a cryptographically strong random number from `min` | ||
# (inclusive) to `max` (inclusive). | ||
def rand(min, max): | ||
delta = max - min | ||
result = min + randbelow(delta + 1) | ||
return result | ||
|
||
def main(): | ||
min = int(sys.argv[1]) | ||
max = int(sys.argv[2]) | ||
result = rand(min, max) | ||
eprint('min=%d; max=%d; result=%d' % (min, max, result)) | ||
print(result) | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env bash | ||
|
||
pubDate=$(date +'%Y-%m-%d'); | ||
(printf "${pubDate}: "; ./rng.py 1 5) >> data/from-01-to-05.txt; | ||
(printf "${pubDate}: "; ./rng.py 1 10) >> data/from-01-to-10.txt; | ||
(printf "${pubDate}: "; ./rng.py 1 15) >> data/from-01-to-15.txt; | ||
(printf "${pubDate}: "; ./rng.py 1 20) >> data/from-01-to-20.txt; | ||
(printf "${pubDate}: "; ./rng.py 1 25) >> data/from-01-to-25.txt; | ||
(printf "${pubDate}: "; ./rng.py 1 30) >> data/from-01-to-30.txt; | ||
(printf "${pubDate}: "; ./rng.py 1 35) >> data/from-01-to-35.txt; | ||
(printf "${pubDate}: "; ./rng.py 1 40) >> data/from-01-to-40.txt; | ||
(printf "${pubDate}: "; ./rng.py 1 45) >> data/from-01-to-45.txt; | ||
(printf "${pubDate}: "; ./rng.py 1 50) >> data/from-01-to-50.txt; | ||
(printf "${pubDate}: "; ./rng.py 1 55) >> data/from-01-to-55.txt; | ||
(printf "${pubDate}: "; ./rng.py 1 60) >> data/from-01-to-60.txt; | ||
(printf "${pubDate}: "; ./rng.py 1 65) >> data/from-01-to-65.txt; | ||
(printf "${pubDate}: "; ./rng.py 1 70) >> data/from-01-to-70.txt; | ||
(printf "${pubDate}: "; ./rng.py 1 75) >> data/from-01-to-75.txt; | ||
(printf "${pubDate}: "; ./rng.py 1 80) >> data/from-01-to-80.txt; | ||
(printf "${pubDate}: "; ./rng.py 1 85) >> data/from-01-to-85.txt; | ||
(printf "${pubDate}: "; ./rng.py 1 90) >> data/from-01-to-90.txt; | ||
(printf "${pubDate}: "; ./rng.py 1 95) >> data/from-01-to-95.txt; | ||
(printf "${pubDate}: "; ./rng.py 1 100) >> data/from-01-to-100.txt; |