On Feb 1, 2008 4:11 PM, Nick Vanderweit <[EMAIL PROTECTED]> wrote:
> #!/usr/bin/env python
> import sys
> from random import *
>
> rulefile = open(sys.argv[1], "r")
> rules = []
> while 1:
>         x = rulefile.readline()
>         if not len(x):
>                 break
>         rules.append(x)
> length = len(rules)
> print rules[SystemRandom().randint(0,length-1)]
>

Prettier:

#!/usr/bin/env python
import sys
from random import *

rulefile = open(sys.argv[1], "r")
print SystemRandom().choice(rule for rule in rulefile if rule)

Reply via email to