randomly generate n of each of two types

Paul Rubin http
Mon Feb 12 02:09:39 EST 2007


Steven D'Aprano <steve at REMOVEME.cybersource.com.au> writes:
> Ah, I see what you mean... you're reminding me that the Original Poster
> seems to want a biased set of almost-but-not-quite-randomly chosen
> values, so that random_values(1) must return one each of True and False
> and never True, True or False, False.

I thought that was what was specified, "generate n of each of two
types".  So if n=10 and the two types are true and false, generate 10
trues and 10 falses.  random.shuffle is the most direct way to do it
but I gave another approach that doesn't use auxiliary space except
for a few variables.



More information about the Python-list mailing list