All Samples(882) | Call(753) | Derive(0) | Import(129)
Chooses k unique random elements from a population sequence. Returns a new list containing elements from the population while leaving the original population unchanged. The resulting list is in selection order so that all sub-slices will also be valid random samples. This allows raffle winners (the sample) to be partitioned into grand prize and second place winners (the subslices). Members of the population need not be hashable or unique. If the population contains repeats, then each occurrence is a possible selection in the sample. To choose a sample in a range of integers, use xrange as an argument. This is especially fast and space efficient for sampling from a large population: sample(xrange(10000000), 60)
src/a/t/atma-HEAD/trunk/examples/process/test2.py atma(Download)
checkbox2.children.append('checked')
checkboxgroupOptions = ['1','2','3']
checkboxgroupValues = random.sample(checkboxgroupOptions, random.randint(0,len(checkboxgroupOptions)))
selectOptions = ['1','2','11','12','21','22']
selectmultipleValues = random.sample(selectOptions, random.randint(0,len(selectOptions)))
selectone = random.sample(selectOptions, random.randint(0,len(selectOptions)))
src/a/t/atma-HEAD/examples/process/test2.py atma(Download)
checkbox2.children.append('checked')
checkboxgroupOptions = ['1','2','3']
checkboxgroupValues = random.sample(checkboxgroupOptions, random.randint(0,len(checkboxgroupOptions)))
selectOptions = ['1','2','11','12','21','22']
selectmultipleValues = random.sample(selectOptions, random.randint(0,len(selectOptions)))
selectone = random.sample(selectOptions, random.randint(0,len(selectOptions)))
src/s/h/shedskin-HEAD/examples/mastermind2.py shedskin(Download)
def s_bestinfo(i, possibles):
if i == 0:
return s_trynodup(i, possibles)
plays = random.sample(possibles, min(20, len(possibles)))
_, play = max([(utility(play, possibles), play) for play in plays])
return play
def s_worstinfo(i, possibles):
if i == 0:
return s_trynodup(i, possibles)
plays = random.sample(possibles, min(20, len(possibles)))
def s_samplebest(i, possibles):
if i == 0:
return s_trynodup(i, possibles)
if len(possibles) > 150:
possibles = random.sample(possibles, 150)
plays = possibles[:20]
elif len(possibles) > 20:
plays = random.sample(possibles, 20)
src/a/t/atma-HEAD/trunk/examples/basics/root/samplejson.py atma(Download)
a = dict()
a['alpha'] = random.random()
a['bravo'] = random.gauss(1,1)
a['charlie'] = random.sample(range(30),random.randint(10,20))
return pprint.pformat(a)
src/a/t/atma-HEAD/examples/basics/root/samplejson.py atma(Download)
a = dict()
a['alpha'] = random.random()
a['bravo'] = random.gauss(1,1)
a['charlie'] = random.sample(range(30),random.randint(10,20))
return pprint.pformat(a)
src/d/a/data-type-tables-HEAD/examples/00.populate.py data-type-tables(Download)
while i < 100:
p = Product()
# when these save, Category relationship saving messes up
p.name = ''.join(random.sample('abcdefghijklmnopqrstuvwxyz ', 15))
p.description = ''.join(random.sample('abcdefghijklmnopqrstuvwxyz ', 20))
p.price = str(decimal.Decimal(random.randrange(10000))/100)
category = random.sample(categories, 1)[0]
src/r/h/rhnsqa_python-HEAD/src/PyUnit_Sample.py rhnsqa_python(Download)
def testsample(self):
self.assertRaises(ValueError, random.sample, self.seq, 20)
for element in random.sample(self.seq, 5):
self.assert_(element in self.seq)
#if __name__ == '__main__':
# unittest.main()
src/p/y/pytoaster-HEAD/tests/sample/sampletest.py pytoaster(Download)
def test_sample(self):
self.assertRaises(TypeError, random.sample, (self.seq,20))
for element in random.sample(self.seq, 5):
self.assertTrue(element in self.seq)
src/p/y/python-ldapdict-HEAD/trunk/test/scripts/testexample.py python-ldapdict(Download)
def testsample(self):
self.assertRaises(ValueError, random.sample, self.seq, 20)
for element in random.sample(self.seq, 5):
self.assert_(element in self.seq)
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestSequenceFunctions)
src/w/i/willow-HEAD/example_ratio_bias.py willow(Download)
def colors(fmt, n, k):
sample = random.sample(range(n),k)
return ",".join([ fmt % i for i in range(n) if not i in sample ])
white = (colors("#A td:eq(%d)", 100, a)+","+
colors("#B td:eq(%d)", 10, b)+","+
colors("#C td:eq(%d)", 100, c)+","+
colors("#D td:eq(%d)", 10, d))
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Next