The way to handle files with spaces is to use the `-print0` directive for GNU find, and the `-d` option for bash's `read` command. It's also imperitive to quote the `"$variable"`
find pics/ -type f -print0 | while IFS= read -rd "" filename; do
v=$((RANDOM % 2))
if (( v == 0 )); then
cp "$filename" dups/$RANDOM.jpg
fi
done
The `IFS=` and `-r` bits are to ensure that spaces and backslashes are handled properly by the `read` command.
Inside `(( ... ))` arithmetic expressions, you can give shell variables without the `$`.