Random number from webcam and hash
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
#! /bin/env bash | |
number_contestants=$1 | |
# convert to hexadecimal | |
number_contestants=$(echo "ibase=10 ; obase=16 ; $number_contestants" | bc) | |
# take image | |
ffmpeg -f v4l2 -i /dev/video0 -frames:v 1 -y foo.png | |
# md5sum it and extract the value | |
md5=$(md5sum foo.png | cut -d" " -f1) | |
# uppercase the string | |
md5=$(echo $md5 | tr a-z A-Z) | |
# and the winner is.... | |
echo "scale=0 ; ibase=16 ; $md5 % $number_contestants" | bc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment