• Facebook
  • Twitter
  • Reddit
  • StumbleUpon
  • Digg
  • email

All Samples(5377)  |  Call(4752)  |  Derive(0)  |  Import(625)
Choose a random element from a non-empty sequence.

src/s/h/shedskin-HEAD/examples/genetic.py   shedskin(Download)
# (c) Bearophile
#
# genetic algorithm
 
from random import random, randint, choice
from math import sin, pi
from copy import copy 
    def mutatePop(self):
        nmutations = int(round(self.popSize * self.genomeSize * self.geneMutationProb))
        for i in xrange(nmutations):
            individual = choice(self.population) 
            gene = randint(0, self.genomeSize-1)
            individual.genome[gene] = not individual.genome[gene] 
 
    def tounamentSelectionPop(self):
        pop2 = []
        for i in xrange(self.popSize):
            individual1 = choice(self.population) 
            individual2 = choice(self.population)
    def crossingOverPop(self):
        nCrossingOver = int(round(self.popSize * self.crossingOverProb))
        for i in xrange(nCrossingOver):
            ind1 = choice(self.population) 
            ind2 = choice(self.population) 
            crossPosition = randint(0, self.genomeSize-1)
            for j in xrange(crossPosition+1):

src/y/d/ydbf-HEAD/doc/examples/gendbf.py   ydbf(Download)
import sys
import ydbf
from decimal import Decimal
from random import randint, choice
from datetime import date
 
def get_n_random(size, dec):
    if force_ascii:
        alph = alphabet[0]
    else:
        alph = choice(alphabet)
    size = randint(size/2, size)
    while len(c) < size:
        c += choice(alph['consonants']) + choice(alph['vowels'])
        if choice((False, False, False, False, False, True)):
def get_l_random(size, dec):
    assert size == 1
    return choice((True, False))
 
def get_rec(fields_struct):
    rec = {}
    for name, typ, size, dec in fields_struct:
        assert typ in ('N', 'D', 'C', 'L')
        getter = globals().get("get_%s_random" % typ.lower())
        if not callable(getter):
            raise ValueError("Cannot get data getter for DBF type %s (field %s)" % (typ, name))
        value = getter(size, dec)
        # 10% of records -- None
        rec[name] = choice([value for _ in xrange(9)] + [None])
    name = str(get_c_random(11, 0, force_ascii=True).replace(u' ', '_'))
    # most popular field type is a numeric
    # next string, next date and the last -- logical
    typ = choice(('N', 'N', 'N', 'N', 'C', 'C', 'C', 'D', 'D', 'L'))
    size = randint(*size_limits[typ])
    dec = 0
    if typ == 'N' and size > 6:
        rand_dec = randint(0, size/2)
        dec = choice((0, rand_dec))

src/s/h/shedskin-HEAD/examples/mastermind2.py   shedskin(Download)
def s_allrand(i, possibles):
    return random.choice(possibles)
 
def s_trynodup(i, possibles):
    for j in xrange(20):
        g = random.choice(possibles)
        if nodup(g):
def eval_strategy(name, strategy):
    start = clock()
    data = [rungame(random.choice(searchspace), strategy, verbose=False) for i in xrange(TRIALS)]
    print 'mean=%.2f %r  %s n=%d dig=%d' % (average(data), counts(data), name, len(data), DIGITS)
    print 'Time elapsed %.2f' % (clock() - start,)
 
def main():

src/m/y/myspaceid-python-sdk-HEAD/myspaceid-python-sdk/samples/google-app-engine/openid-combined-consumer/gmemsess.py   myspaceid-python-sdk(Download)
 
        # Create a new session ID
        # There are about 10^14 combinations, so guessing won't work
        self._sid=random.choice(_sidChars)+random.choice(_sidChars)+\
                        random.choice(_sidChars)+random.choice(_sidChars)+\
                        random.choice(_sidChars)+random.choice(_sidChars)+\
                        random.choice(_sidChars)+random.choice(_sidChars)+\
                        random.choice(_sidChars)+random.choice(_sidChars)

src/m/y/myspaceid-python-sdk-HEAD/myspaceid-python-sdk/samples/google-app-engine/oauth/gmemsess.py   myspaceid-python-sdk(Download)
 
        # Create a new session ID
        # There are about 10^14 combinations, so guessing won't work
        self._sid=random.choice(_sidChars)+random.choice(_sidChars)+\
                        random.choice(_sidChars)+random.choice(_sidChars)+\
                        random.choice(_sidChars)+random.choice(_sidChars)+\
                        random.choice(_sidChars)+random.choice(_sidChars)+\
                        random.choice(_sidChars)+random.choice(_sidChars)

src/y/d/YDbf-0.3rc1/doc/examples/gendbf.py   YDbf(Download)
import sys
import ydbf
from decimal import Decimal
from random import randint, choice
from datetime import date
 
def get_n_random(size, dec):
    if force_ascii:
        alph = alphabet[0]
    else:
        alph = choice(alphabet)
    size = randint(size/2, size)
    while len(c) < size:
        c += choice(alph['consonants']) + choice(alph['vowels'])
        if choice((False, False, False, False, False, True)):
def get_l_random(size, dec):
    assert size == 1
    return choice((True, False))
 
def get_rec(fields_struct):
    rec = {}
    for name, typ, size, dec in fields_struct:
        assert typ in ('N', 'D', 'C', 'L')
        getter = globals().get("get_%s_random" % typ.lower())
        if not callable(getter):
            raise ValueError("Cannot get data getter for DBF type %s (field %s)" % (typ, name))
        value = getter(size, dec)
        # 10% of records -- None
        rec[name] = choice([value for _ in xrange(9)] + [None])
    name = str(get_c_random(11, 0, force_ascii=True).replace(u' ', '_'))
    # most popular field type is a numeric
    # next string, next date and the last -- logical
    typ = choice(('N', 'N', 'N', 'N', 'C', 'C', 'C', 'D', 'D', 'L'))
    size = randint(*size_limits[typ])
    dec = 0
    if typ == 'N' and size > 6:
        rand_dec = randint(0, size/2)
        dec = choice((0, rand_dec))

src/a/t/atma-HEAD/trunk/examples/process/test2.py   atma(Download)
 
        return n('command', {'type': 'populate-values'},
            n('data-textinput', {'id':'textinput1'}, str(random.random())),
            n('data-textareainput', {'id':'textareainput1'}, str(random.choice(self.quotes))),
            checkbox1,
            checkbox2,
            n("data-radiogroup",{"id":"radiogroup1"}, str(random.randint(0,3))),

src/g/r/grease-0.2/examples/blasteroids3.py   grease(Download)
    def __init__(self, world, radius=45, position=None, parent_velocity=None, points=25):
        if position is None:
            self.position.position = (
                random.choice([-1, 1]) * random.randint(50, window.width / 2), 
                random.choice([-1, 1]) * random.randint(50, window.height / 2))
        else:
            self.position.position = position

src/g/r/grease-0.2/examples/blasteroids2.py   grease(Download)
    def __init__(self, world, radius=45):
        self.position.position = (
            random.choice([-1, 1]) * random.randint(50, window.width / 2), 
            random.choice([-1, 1]) * random.randint(50, window.height / 2))
        self.movement.velocity = (random.gauss(0, 700 / radius), random.gauss(0, 700 / radius))
        self.movement.rotation = random.gauss(0, 15)
        verts = [(random.gauss(x * radius, radius / 7), random.gauss(y * radius, radius / 7))

src/a/t/atma-HEAD/examples/process/test2.py   atma(Download)
 
        return n('command', {'type': 'populate-values'},
            n('data-textinput', {'id':'textinput1'}, str(random.random())),
            n('data-textareainput', {'id':'textareainput1'}, str(random.choice(self.quotes))),
            checkbox1,
            checkbox2,
            n("data-radiogroup",{"id":"radiogroup1"}, str(random.randint(0,3))),

  1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9  Next