Walter Bright wrote: > bearophile wrote: >> Think about a "Bulls and cows" game (it's a task of Rosettacode site), >> it's >> similar to MasterMind, at the beginning you need to generate the >> secret key, >> four random distinct digits, that later are used in the program, the >> user has >> to guess them using the number of right items in the right place, or >> right >> items in the wrong place. To generate the key in Python you may use >> "".join(sample(d, 4)). > > Generate a 4 digit random integer and convert it to a string. It's > probably a lot more efficient than the Python version.
Except that the Python version ensures that you don't have the same
digit twice, which just generating a 4 digits random integer won't...
Jerome
--
mailto:[email protected]
http://jeberger.free.fr
Jabber: [email protected]
signature.asc
Description: OpenPGP digital signature
