11.09.05

Flipping a coin

Posted in computers at 3:54 pm by Haris

Here’s my new favorite way for flipping a coin: In a command line, type:

echo "`date "+%S"`%2" | bc

and press enter, or even better, from a file in TextMate, type this in a line and press Control-R.

What’ s your favorite way?

Later

4 Comments »

  1. Sameer said,

    November 9, 2005 at 10:56 pm

    This is not very random. You might as well look at your watch and type in 1 or 0.

    This is much much better.
    http://www.random.org/cgi-bin/randnum?num=1&min=0&max=1&col=1

  2. Haris said,

    November 10, 2005 at 2:35 pm

    Yeah, but it requires an internet connection. :-)

    We actually use the other method to create a script that would load a different TextMate theme each time it is ran.

    Why isn’t there a shell command to generate a random number?

  3. Allan Odgaard said,

    November 11, 2005 at 9:11 am

    From shell there’s /dev/random, but it’s verbose to pick the first byte from that stream (and work with it).

    So how about: ruby -e ‘puts rand.round’

    Rand gives a number between 0 and 1, so rounding it should be the coin flip.

  4. Haris said,

    November 11, 2005 at 5:11 pm

    I like the ruby method, it almost forces me to learn more ruby.

    Indeed the /dev/random approach is a bit too verbose:

    /dev/random bs=1 count=1 2>/dev/null|hexdump -e '/1 "%u"'

    as you mentioned in the mailing list.

    But it’s good to know it’s there.

Leave a Comment