Random string samples & unicode - Reprise
"Jérôme M. Berger"
jeberger at free.fr
Sat Sep 18 00:59:18 PDT 2010
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:jeberger at free.fr
http://jeberger.free.fr
Jabber: jeberger at jabber.fr
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20100918/c174e12f/attachment.pgp>
More information about the Digitalmars-d
mailing list