Random string samples & unicode - Reprise

Kagamin spam at here.lot
Sun Sep 12 23:16:41 PDT 2010


bearophile Wrote:

> > string that contains two random but distinct digits?
> 
> It's not easy to give a good answer to this question. In Python it's normal code, almost common.
> Google Code Search gives 27 answers:
> http://www.google.com/codesearch?hl=en&lr=&q=%22.join%28sample%28%22+lang%3Apython&sbtn=Search
> 

Well, captcha is a good example, but simple to!string(rand()) is ok as a password generator.

> 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)).
> 
Why they're chars but not numbers?


More information about the Digitalmars-d mailing list