Skip to content

Commit

Permalink
Add random number generator script + GitHub Actions workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiasbynens committed Jul 9, 2022
0 parents commit 420069a
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/update.yml
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
24 changes: 24 additions & 0 deletions rng.py
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()
23 changes: 23 additions & 0 deletions update.sh
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;

0 comments on commit 420069a

Please sign in to comment.