Created
November 18, 2022 17:00
-
-
Save hexagon5un/472df972efd6a72c1e33fdf047a4b4e3 to your computer and use it in GitHub Desktop.
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