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

All Samples(8859)  |  Call(7670)  |  Derive(40)  |  Import(1149)
random() -> x in the interval [0, 1).

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)
    def mutate(self):
        """Mutate this node."""
        # If we're a terminal node, stop so we don't exceed our depth.
        if self.opcode == OPCODE_NONE:
            return
 
        if random() > 0.5:
    def get_random_node(self, max_depth=MAX_DEPTH):
        """Get a random node from the tree."""
        root = self.genome
        previous_root = root
        choice = 0
        for counter in range(max_depth):
            if root.args and random() > 1 / MAX_DEPTH:

src/p/y/pymol-HEAD/trunk/pymol/examples/devel/cgo08.py   pymol(Download)
from pymol.cgo import *
from pymol import cmd
from random import random, seed
from chempy import cpv
 
# CGO cones
 
    # where the xyz vectors are orthogonal and of length 1.0 or less.
 
    box = box - size
    tmp0 = [ size + random() * box, size + random() * box, size + random() * box ]
    tmp1 = cpv.random_vector()
    tmp2 = cpv.scale(tmp1,box/10)
    tmp1 = cpv.add(tmp2,tmp0)
 
    return [ CONE,
             tmp0[0], tmp0[1], tmp0[2], # coordinates 
             tmp1[0], tmp1[1], tmp1[2],
             (abs(random())*0.4+0.2) * size, # radii
             (abs(random())*0.1+0.01) * size,
             random(), random(), random(), # colors
             (abs(random())*0.4+0.2) * size, # radii
             (abs(random())*0.1+0.01) * size,
             random(), random(), random(), # colors
             random(), random(), random(),
             1.0, 1.0 ]
 
for count in range(50):

src/p/y/pymol-HEAD/pymol/examples/devel/cgo08.py   pymol(Download)
from pymol.cgo import *
from pymol import cmd
from random import random, seed
from chempy import cpv
 
# CGO cones
 
    # where the xyz vectors are orthogonal and of length 1.0 or less.
 
    box = box - size
    tmp0 = [ size + random() * box, size + random() * box, size + random() * box ]
    tmp1 = cpv.random_vector()
    tmp2 = cpv.scale(tmp1,box/10)
    tmp1 = cpv.add(tmp2,tmp0)
 
    return [ CONE,
             tmp0[0], tmp0[1], tmp0[2], # coordinates 
             tmp1[0], tmp1[1], tmp1[2],
             (abs(random())*0.4+0.2) * size, # radii
             (abs(random())*0.1+0.01) * size,
             random(), random(), random(), # colors
             (abs(random())*0.4+0.2) * size, # radii
             (abs(random())*0.1+0.01) * size,
             random(), random(), random(), # colors
             random(), random(), random(),
             1.0, 1.0 ]
 
for count in range(50):

src/p/y/pymol-HEAD/trunk/pymol/examples/devel/cgo07.py   pymol(Download)
from pymol.cgo import *
from pymol import cmd
from random import random, seed
from chempy import cpv
 
# CGO ellipsoids
 
    tmp2 = cpv.normalize(tmp2)
    tmp3 = cpv.normalize(tmp3)
    tmp4 = cpv.normalize(tmp4)
    primary = cpv.scale(tmp2, random())
    secondary = cpv.scale(tmp3,random())
    tertiary = cpv.scale(tmp4,random())
    factor = 1.0 / max( cpv.length(primary), cpv.length(secondary), cpv.length(tertiary))
    primary = cpv.scale(primary, factor)
    secodary = cpv.scale(secondary, factor)
    tertiary = cpv.scale(tertiary, factor)
    return [ ELLIPSOID,
             size + random() * box, size + random() * box, size + random() * box,
             max(random() * size, min_axis),
 
for count in range(100):
#    obj.extend( [ALPHA, random() ] )
    obj.extend( [COLOR, random(), random(), random()] )
    obj.extend( random_ellipsoid(10.0, 1.5, 0.2) )
 
# use more triangles when drawing ellipsoids

src/p/y/pymol-HEAD/pymol/examples/devel/cgo07.py   pymol(Download)
from pymol.cgo import *
from pymol import cmd
from random import random, seed
from chempy import cpv
 
# CGO ellipsoids
 
    tmp2 = cpv.normalize(tmp2)
    tmp3 = cpv.normalize(tmp3)
    tmp4 = cpv.normalize(tmp4)
    primary = cpv.scale(tmp2, random())
    secondary = cpv.scale(tmp3,random())
    tertiary = cpv.scale(tmp4,random())
    factor = 1.0 / max( cpv.length(primary), cpv.length(secondary), cpv.length(tertiary))
    primary = cpv.scale(primary, factor)
    secodary = cpv.scale(secondary, factor)
    tertiary = cpv.scale(tertiary, factor)
    return [ ELLIPSOID,
             size + random() * box, size + random() * box, size + random() * box,
             max(random() * size, min_axis),
 
for count in range(100):
#    obj.extend( [ALPHA, random() ] )
    obj.extend( [COLOR, random(), random(), random()] )
    obj.extend( random_ellipsoid(10.0, 1.5, 0.2) )
 
# use more triangles when drawing ellipsoids

src/m/i/mingus-0.4.2.3/mingus_examples/improviser/improviser.py   mingus(Download)
from mingus.containers import NoteContainer, Note
from mingus.midi import fluidsynth
import time, sys
from random import random, choice, randrange
 
SF2 = "soundfont.sf2"
 
 
		# Create random solo over chord
		if double_time:
			beats = [ random() > 0.5 for x in range((loop % 2 + 1) * 8)]
		else:
			beats = [ random() > 0.5 for x in range(8)]
		t = 0
				if t % 2 == 0:
					n = Note(choice(c).name)
 
				elif random() > 0.5:
					if random() < 0.46:
						n = Note(intervals.second(choice(c).name, key))
					elif random() < 0.46:
 
			# Repeat chord on half of the bar
			if play_chords and t != 0 and loop > chord_start and loop < chord_end:
				if swing and random() > 0.95:
					fluidsynth.play_NoteContainer(c, chord_channel3, randrange(20, 75))
				elif t % (len(beats) / 2) == 0 and t != 0:
					fluidsynth.play_NoteContainer(c, chord_channel3, randrange(20, 75))
				if t % (len(beats) / 2) == 0 and t != 0:
					fluidsynth.play_Note(Note("E", 2), 9, randrange(50,100)) # snare
				else:
					if random() > 0.8 or t == 0:
						fluidsynth.play_Note(Note("C", 2), 9, randrange(20,100)) # bass
 
				if t == 0 and random() > 0.75:
					fluidsynth.play_Note(Note("C#", 3), 9, randrange(60,100)) # crash
 
				if swing:
					if random() > 0.9:
						fluidsynth.play_Note(Note("A#", 2), 9, randrange(50,100)) # hihat open
					elif random() > 0.6:
						fluidsynth.play_Note(Note("A#", 2), 9, randrange(50,100)) # hihat open
					elif random() > 0.6:
						fluidsynth.play_Note(Note("G#", 2), 9, randrange(100,120)) # hihat closed
					if random() > 0.95:
						fluidsynth.play_Note(Note("E", 2), 9,  100) # snare
				elif t % 2 == 0: 
					fluidsynth.play_Note(Note("A#", 2), 9, 100) # hihat open
				else:
					if random() > 0.9:

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 __init__(self, ngenes):
        self.ngenes = ngenes
        self.genome = [random()<0.5 for i in xrange(ngenes)]
        self.fitness = infiniteNeg
    def bin2dec(self, inf=0, sup=0): 
        if sup == 0: sup = self.ngenes - 1 
        result = 0
    def tounamentSelectionPop(self):
        pop2 = []
        for i in xrange(self.popSize):
            individual1 = choice(self.population) 
            individual2 = choice(self.population)
            if random() < self.selectivePressure:
                if individual1.fitness > individual2.fitness:

src/a/t/atma-HEAD/trunk/examples/process/test2.py   atma(Download)
        else:
            selectone = None
 
        currency1 = random.randint(1,9999) + random.random()
        currency2 = random.randint(1,9999) + random.random()
 
        return n('command', {'type': 'populate-values'},
            n('data-textinput', {'id':'textinput1'}, str(random.random())),

src/a/t/atma-HEAD/examples/process/test2.py   atma(Download)
        else:
            selectone = None
 
        currency1 = random.randint(1,9999) + random.random()
        currency2 = random.randint(1,9999) + random.random()
 
        return n('command', {'type': 'populate-values'},
            n('data-textinput', {'id':'textinput1'}, str(random.random())),

src/p/e/peyote-HEAD/examples/julia.py   peyote(Download)
import numpy as np
from noise import pnoise3 as noise
 
from random import randrange, random
from math import pi, cos, sin
 
num = 100
pos = np.zeros((num, 2), dtype='int')
vel = np.zeros((num, 2), dtype='int')
acc = np.zeros((num, 2), dtype='int')
 
R1 = random()
R2 = random()
G1 = random()
R1 = random()
R2 = random()
G1 = random()
G2 = random()
B1 = random()
B2 = random()
noisy = 0.007

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