Thursday, February 18, 2010

Random Python

I don't know why, but this code kept popping into my my brain last night.

import random
def to_be_or_not_to_be():
return random.random() < 0.5

I think it is interesting, because even though it asks a clear question, the answer is... not entirely clear. It is a sad day when one realises his dreams are plagued by source code.


Paul said...

Very awesome :)

respect *= 100

teddlesruss said...

There's no definition of the constant "towel" in there. And the answer always comes out to 0.42, anyway.

Juho Vepsäläinen said...


random.choice((True, False))

is a tad more readable than just random.random. :)

Anonymous said...

Or even:

random.choice(('2b', '!2b'))

to make the answer a tad clearer maybe?

Ludvig Ericson said...

Or even

"!2b"[random.random() > 0.5:]

Popular Posts