Skip to content

Instantly share code, notes, and snippets.

Created November 18, 2022 17:00
What would you like to do?
Random number from webcam and hash
#! /bin/env bash
# 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