dd bs="$(blockdev --getsize64 "$device")" count=1 if=/dev/urandom of=random-file
dd if=random-file of="$device"
cmp random-file "$device"
EDIT: I'm not sure if my use of dd's bs and count is a good idea, though. It might be better to do:
head -c "$(blockdev --getsize64 "$device")" /dev/urandom > random-file
For that second line, I often prefer to do:
pv random-file > "$device"
EDIT 2: As discussed in other threads, one should make sure to invalidate the kernel's cache of the device between steps 2 and 3. My safest bet on how to do that is to reboot the computer.