Skip to content

Instantly share code, notes, and snippets.

@hexagon5un
Created November 18, 2022 17:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hexagon5un/472df972efd6a72c1e33fdf047a4b4e3 to your computer and use it in GitHub Desktop.
Save hexagon5un/472df972efd6a72c1e33fdf047a4b4e3 to your computer and use it in GitHub Desktop.
Random number from webcam and hash
#! /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