Skip to content

Instantly share code, notes, and snippets.

@azet
Created March 8, 2012 11:04
Show Gist options
  • Save azet/2000457 to your computer and use it in GitHub Desktop.
Save azet/2000457 to your computer and use it in GitHub Desktop.
we have an array of 3 entries for e.g. restaurants, execute this a couple of times until it matches something, decision made.
while :; do for i in `seq 1 3`; do if ( echo -n 'bit match: '; dd if=/dev/urandom count=128 bs=1 >& /dev/null | grep -c '1' ) echo -e "\n\nyour match: $i" && break 2; done; done
@azet
Copy link
Author

azet commented Mar 8, 2012

example:
1 = chinese
2 = sushi
3 = pizza

  • change seq 1 3 for a bigger array size.
  • decreasing the count= parameter will take longer, with higher randomization.
  • you can also change the blocksize bs= parameter, if you wish to.

update:

this is a sh/bash compliant version (output is not as nice though):

while :; do for i in `seq 1 3`; do if ( echo -n 'bit match: '; dd if=/dev/urandom count=128 bs=1 | grep -c '1' ); then echo -e "\n\nyour match: $i" && break 2; fi; done; done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment