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

All Samples(10569)  |  Call(9444)  |  Derive(0)  |  Import(1125)
Return random integer in range [a, b], including both end points.
        

src/s/h/shedskin-HEAD/examples/genetic2.py   shedskin(Download)
#!/usr/bin/env python
 
# placed in the public domain by Stavros Korokithakis
 
import time
import copy
from random import randrange, randint, seed, random, choice, triangular
def make_random_genome(node, depth=0):
    if depth >= MAX_DEPTH or random() > 0.7:
        node.opcode = OPCODE_NONE
        node.args = None
        node.value = randrange(MUX_SIZE + DATA_SIZE)
    else:
        node.opcode = randint(OPCODE_AND, OPCODE_IF)

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 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/p/y/pyquery-HEAD/examples.py   pyquery(Download)
'''
 
import itertools
from random import seed, randint
seed('Example CAP Database')
 
#Consider the Customers-Agents-Products (CAP) database with schema below.
#orders += list(Order(customers[t[0]], agents[t[1]], products[t[2]], randint(0,100)) for t in itertools.product(range(4), repeat=3))
 
orders = [
        Order(customers[0], agents[0], products[0], randint(0,100)),
        Order(customers[0], agents[1], products[0], randint(0,100)),
        Order(customers[0], agents[2], products[0], randint(0,100)),
        Order(customers[1], agents[3], products[1], randint(0,100)),
        Order(customers[2], agents[0], products[3], randint(0,100)),
        Order(customers[3], agents[1], products[2], randint(0,100)),
        Order(customers[3], agents[2], products[1], randint(0,100)),
        Order(customers[1], agents[3], products[2], randint(0,100)),
        Order(customers[3], agents[3], products[2], randint(0,100)),
        Order(customers[0], agents[3], products[2], randint(0,100)),
        Order(customers[4], agents[3], products[2], randint(0,100)),
        Order(customers[3], agents[3], products[2], randint(0,100)),
        Order(customers[0], agents[3], products[2], randint(0,100)),
        Order(customers[4], agents[3], products[2], randint(0,100)),
        Order(customers[5], agents[3], products[2], randint(0,100)),
        Order(customers[4], agents[1], products[1], randint(0,100)),
        Order(customers[2], agents[1], products[1], randint(0,100)),
    ]

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):
    assert size < 20, "number cannot be longer than 20 digits (got %s)" % size
    assert dec < size, "size (%s) must be bigger than dec (%s)" % (size, dec)
    n = randint(0, 10**(size-dec-1)-1)
    if dec:
        if size-dec-1 == 0:
            dec = dec -1
        decimal_part = [int(y) for y in str(randint(1, 10**(dec-1)))]
def get_d_random(size, dec):
    try:
        return date(randint(1899, 2030), randint(1,12), randint(1,31))
    except ValueError:
        return get_d_random(size, dec)
 
def get_c_random(size, dec, force_ascii=False):
        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)):
    # 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)

src/p/y/PyMT-0.5.1/examples/apps/fridgeletter/fridgeletter.py   PyMT(Download)
import os
from pymt import *
from random import randint, random
 
# PYMT Plugin integration
IS_PYMT_PLUGIN = True
PLUGIN_TITLE = 'Fridge letter'
            if chr(c) in 'AEUIO':
                count = 4
            for i in xrange(0, count):
                color = map(lambda x: x/255., (randint(100,255), randint(100,255), randint(100,255), 255))
                l = FridgeLetterAtomic(letter=chr(c), color=color)
                if w:
                    l.pos = randint(0, w.width), randint(0, w.height)

src/p/r/practice_python-HEAD/bookexample/src/bvista/b15_2_gendata.py   practice_python(Download)
Created on 2009-5-17
 
'''
from random import randint, choice
from string import lowercase
from sys import maxint
from time import ctime
 
doms = ('com', 'edu', 'net', 'org', 'gov')
 
for i in range(randint(5, 10)):
    dtint = randint(0, maxint-1)
    dtint = randint(0, maxint-1)
    ctime(dtint)
 
    shoter = randint(4, 7)
    em = ''
    for j in range(shoter):
        em += choice(lowercase)
 
    longer = randint(shoter, 12)

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):
    assert size < 20, "number cannot be longer than 20 digits (got %s)" % size
    assert dec < size, "size (%s) must be bigger than dec (%s)" % (size, dec)
    n = randint(0, 10**(size-dec-1)-1)
    if dec:
        if size-dec-1 == 0:
            dec = dec -1
        decimal_part = [int(y) for y in str(randint(1, 10**(dec-1)))]
def get_d_random(size, dec):
    try:
        return date(randint(1899, 2030), randint(1,12), randint(1,31))
    except ValueError:
        return get_d_random(size, dec)
 
def get_c_random(size, dec, force_ascii=False):
        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)):
    # 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)

src/s/h/shedskin-HEAD/examples/oliva2.py   shedskin(Download)
This program requires Python and ShedSkin (http://shedskin.sourceforge.net).
"""
 
from random import random, randint
 
 
class SavePGMlines:
    i = 10
    for j in xrange(20):
        a[i] = 1.0
        i += randint(10, 60)
        if i >= nx:
            break
 

src/p/y/python-visual-HEAD/examples/planar.py   python-visual(Download)
from visual import *
from random import uniform, randint
 
scene.forward = (-0.25,-0.25,-1)
 
nboxes = 8
nlinks = 16
# Create some random links:
links = []
for l in range(nlinks):
  i = randint(0,nboxes-1)
  j = randint(0,nboxes-1)
  c = curve( ends=[nodes[i].pos,nodes[j].pos], radius=0.2 )
  c.red = 0

src/p/y/PyMT-0.5.1/examples/games/bubblebomb/bubblebomb.py   PyMT(Download)
import os
from pymt import *
from OpenGL.GL import *
from random import random, randint
 
current_dir = os.path.dirname(__file__)
 
    def __init__(self, **kwargs):
        super(Bomb, self).__init__(**kwargs)
        self.r = 30
        self.moved = False
        self.speed = 200
        self.level = kwargs.get('level')
        self.dx, self.dy = map(lambda x: randint(-self.speed, self.speed), xrange(2))
    def spawn(self):
        self.nextspawn -= (getFrameDt() * .5) * self.spawnspeed
        if self.nextspawn < 0:
            c = ('red', 'blue')[randint(0, 1)]
            b = Bomb(color=c, level=self.level)
            self.nextspawn = 1.
            w = self.get_parent_window()

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