#!/bin/bash

file=${1:-'-'}
removefile=false
if [[ - == $file ]]; then
    file=$(mktemp /tmp/XXXXXXXXX)
    cat > $file
    removefile=true
fi
randnum=$(od -An -v -tu4 -N4 /dev/urandom)
# ^ -An -- don't print addresses
# ^ -v -- don't display duplicates specially
# ^ -tu4 -- format as 4-byte unsigned
# ^ -N4 -- read 4 bytes

lines=$(wc -l $file | awk '{print $1}' )
randline=$(( randnum % (lines + 1) ))
head -n $randline $file | tail -n 1
$removefile && rm -f $file

