示例#1
0
def random_walk(npc):
    randomX = math.random() * (npc.MaxRoam.X * Constants.TILE_SIZE)
    randomY = math.random() * (npc.MaxRoam.Y * Constants.TILE_SIZE)

    signx = -1 if math.random() < .5 else 1
    signy = -1 if math.random() < .5 else 1

    npc.GoTo(Vector(randomX * signX, randomY * signY))
示例#2
0
def Maison(ID):

        typeShare = int(math.random()*3)+1
        cagnotte
        tauxConso = int(math.random()*5001) + 7000 # taux à l'année entre 7 000 et 12 000 kWh

        initProduct = int(math.random()*5001) + 5000 #production par an entre 5 000 et 10 000 kWh
        energie = (initProduct - tauxConso )/365.25
示例#3
0
def pointMutate(genome):
    step = genome.mutationRates["step"]

    for i in range(genome.genes):
        gene = genome.genes[i]
        if math.random() < PerturbChance:
            gene.weight = gene.weight + math.random() * step * 2 - step
        else:
            gene.weight = math.random() * 4 - 2
示例#4
0
def Economics():

    ecoPb = False #boucle qui lance un problème éco aléatoirement 
    while eco == false:
        proba = math.random()
        if proba > 0.90:
            ecoPb = True
    typePb = int(math.random()*2)+1 #1 : offre qui augmente, prix qui baisse #2 : offre qui diminue, prix qui augmente
    if typePb == 1:
        #fonction de market qui augmente le prix
    else:
示例#5
0
def get_sample(ref, radius, t_diff):
    rand_angle = 2 * math.pi * random.random()
    samp_rad = radius * random.random()
    x = samp_rad * math.cos(rand_angle)
    y = samp_rad * math.sin(rand_angle)
    t = ref.t + t_diff * (2 * math.random() - 1)
    return STPoint(x, y, t)
示例#6
0
def crossover(g1, g2):
    # Make sure g1 is the highest fitness genome
    if g2.fitness > g1.fitness:
        tempg = g1
        g1 = g2
        g2 = tempg
    child = newGenome()

    innovations2 = {}
    # for gene in g2.genes:
    for i in range(len(g2.genes)):
        gene = g2.genes[i]
        innovations2[gene.innovation] = gene

    for i in range(len(g1.genes)):
        gene1 = g1.genes[i]
        gene2 = innovations2[gene1.innovation]

        if gene2 != None and math.random(2) == 1 and gene2.enabled:
            # table.insert(child.genes, copyGene(gene2))
            child.genes.append(copyGene(gene2))
        else:
            # table.insert(child.genes, copyGene(gene1))
            child.genes.append(copyGene(gene1))

    child.maxneuron = math.max(g1.maxneuron, g2.maxneuron)

    child.mutationRates = g1.mutationRates.copy()
    """
    for mutation, rate in pairs(g1.mutationRates) do
        child.mutationRates[mutation] = rate
    """
    return child
示例#7
0
def linkMutate(genome, forceBias):
    neuron1 = randomNeuron(genome.genes, False)
    neuron2 = randomNeuron(genome.genes, True)

    newLink = newGene()
    if neuron1 <= inputs_count and neuron2 <= inputs_count:
        return

    if neuron2 <= inputs_count:
        # Swap output and input
        temp = neuron1
        neuron1 = neuron2
        neuron2 = temp

    newLink.into = neuron1
    newLink.out = neuron2

    if forceBias:
        newLink.into = inputs_count

    if containsLink(genome.genes, newLink):
        return

    newLink.innovation = newInnovation()
    newLink.weight = math.random() * 4 - 2

    genome.genes.append(newLink)
示例#8
0
文件: camera.py 项目: airtx/PyWC3
 def pan_z_instant(self,z):
     if self.shake_amount > 0:
         z += (math.random() - 0.5) * self.shake_amount
         self.shake_amount *= self.shake_dim
         if self.shake_amount < 10: self.shake_amount = 0
     if GetPlayerId(GetLocalPlayer()) in self.players:
         SetCameraField(CAMERA_FIELD_ZOFFSET, z, - 0.01)
         SetCameraField(CAMERA_FIELD_ZOFFSET, z, 0.01)
示例#9
0
    def new_game(cls, user, card):
        """Creates and returns a new game"""

        game = Game(user=user,
                    cards=list(math.random(range(1, 11))),
                    game_over=False)
        game.put()
        return game
示例#10
0
	def generate(self):
		count, product = 0, 1.0
		elambda = math.exp(-self.mean)

		while product > elambda:
			product *= math.random()
			count += 1

		return count - 1
示例#11
0
def enableDisableMutate(genome, enable):
    candidates = []
    for gene in genome.genes:
        if not gene.enabled == enable:
            candidates.append(gene)

    if  len(candidates) == 0:
        return

    gene = candidates[math.random(1,  len(candidates))]
    gene.enabled = not gene.enabled
示例#12
0
文件: camera.py 项目: airtx/PyWC3
 def on_period(self):
     z = self.z
     if self.shake_amount > 0:
         z += (math.random() - 0.5) * self.shake_amount
         self.shake_amount *= self.shake_dim
         if self.shake_amount < 10: self.shake_amount = 0
     if GetPlayerId(GetLocalPlayer()) in self.players and self.lock_z:
         if 'z' not in self.transitions or not self.transitions['z'].active:
             z += GetCameraField(CAMERA_FIELD_ZOFFSET) - GetCameraTargetPositionZ()
             SetCameraField(CAMERA_FIELD_ZOFFSET, z, - 0.01)
             SetCameraField(CAMERA_FIELD_ZOFFSET, z, 0.01)
示例#13
0
def translation_circuit(signal, regions, lights = 0, board = False):
    # r = num_lights if num_lights < r
    vals = [len(signals)][r]

    # TODO: This is where the signal gets filtered into interpretable data
    # filtered_signal = []
    # TODO: This is where the filtered signal gets converted into RGB values

    if board:
        for i in range(1, r+1, type=float):

    return [math.random(255) for val in vals]# placeholder for random values
示例#14
0
def translation_rgb(signal, regions, lights = 0, grad_type = 0, board = False):
    rgb_vals = [r][3]

    # TODO: This is where the signal gets filtered into interpretable data
    # filtered_signal = []
    # TODO: This is where the filtered signal gets converted into RGB values

    if
    return [[math.random(255) for val in vals] for vals in rgb_vals]# placeholder for random values

def output_lights(light_vals):
    return # TODO?
    def calculateSpawn(self):
        if self.TIME > 25:
            spawnLevel = int((self.roadPop / 10) * math.random())
        elif self.TIME == 25:
            spawnLevel = self.roadPop / 10
        elif self.TIME < 25:
            spawnLevel = self.roadPop / 10

        if self.TIME > 15 and self.TIME < 25 or self.TIME > 60 and self.TIME < 75:
            #use rush hour multiplier
            return spawnLevel * self.RH_multiplier
        else:
            return spawnLevel
示例#16
0
    def atencionCliente(self):
        catidad = 0
        self.reloj = self.reloj + 1
        self.eventos = self.eventos + 1
        self.cajeros = False
        self.agregarEvento()
        self.cantidad = int(math.random() * 3000) + 100
        if self.dinero < self.cantidad:
            self.abastecimientoCajero()
        else:
            self.dinero = self.cantidad
            self.satisfechos = self.satisfechos + 1
            self.salidaCliente()

        if (self.fila > 0):
            self.fila = self.fila - 1
示例#17
0
 def submit(self):
     m = hashlib.sha256()
     m.update(math.random(10000))
     self.digest = self.hash.hexdigest()
     with self.client.post(
         "/api/v1/submit",
         {
             "jsonrpc": "2.0",
             "id": 0,
             "method": "submit",
             "params": {"checksum": self.digest},
         }, 
             catch_response=True
     ) as response:
         if response.status_code != 200:
             response.failure("The stamp response was an eror")
def estrai(lProb):
    pTotVincenti = sum(lProb)
    numRnd = m.random()
    # numRnd = 1e-9
    # print "numRnd ", numRnd
    if numRnd < pTotVincenti:
        cumulata = lProb[0]
        i = 1
        while i < len(lProb):
            # print "cumul ", cumulata, " premio ", i
            if numRnd < cumulata:
                return i - 1
            else:
                cumulata += lProb[i]
                i += 1
        return i - 1
    else:
        return len(lProb)
示例#19
0
def mutate(genome):
    for mutation, rate in genome.mutationRates.items():
        if math.random(1, 2) == 1:
            genome.mutationRates[mutation] = 0.95 * rate
        else:
         genome.mutationRates[mutation] = 1.05263 * rate

    if math.random() < genome.mutationRates["connections"]:
        pointMutate(genome)

    p = genome.mutationRates["link"]

    while p > 0:
        if math.random() < p :
            linkMutate(genome, False)
        p = p - 1

    p = genome.mutationRates["bias"]

    while p > 0:
        if math.random() < p:
            linkMutate(genome, True)
        p = p - 1

    p = genome.mutationRates["node"]

    while p > 0 :
        if math.random() < p:
            nodeMutate(genome)
        p = p - 1

    p = genome.mutationRates["enable"]

    while p > 0:
        if math.random() < p:
            enableDisableMutate(genome, True)
        p = p - 1

    p = genome.mutationRates["disable"]

    while p > 0:
        if math.random() < p:
            enableDisableMutate(genome, False)
        p = p - 1
示例#20
0
def nodeMutate(genome):
    if  len(genome.genes) == 0:
        return

    genome.maxneuron = genome.maxneuron + 1

    gene = genome.genes[math.random(1,  len(genome.genes) )]
    if not gene.enabled:
        return
    gene.enabled = False

    gene1 = copyGene(gene)
    gene1.out = genome.maxneuron
    gene1.weight = 1.0
    gene1.innovation = newInnovation()
    gene1.enabled = True
    genome.genes.append(gene1)

    gene2 = copyGene(gene)
    gene2.into = genome.maxneuron
    gene2.innovation = newInnovation()
    gene2.enabled = True
    genome.genes.append(gene2)
示例#21
0
def randomNeuron(genes, nonInput):
    neurons = [False] * len(inputs_count)
    if not nonInput:
        for i in range(inputs_count):
            neurons[i] = True

    for i in range(inputs_count):
        neurons[MaxNodes + i] = True

    for i in range(len(genes)):
        if not nonInput or genes[i].into > inputs_count:
            neurons[genes[i].into] = True

        if not nonInput or genes[i].out > inputs_count:
            neurons[genes[i].out] = True

    count = inputs_count
    """
    count = 0
    for _, _ in pairs(neurons) do
        count = count + 1
    """

    n = math.random(1, count)

    for k, v in neurons:
        n = n - 1
        if n == 0:
            return k

    """
    for k, v in pairs(neurons) do
        n = n - 1
        if n == 0 then
            return k
    """
    return 0
def randomElement(l):
    s = len(l)

    return l[s * math.random()]
示例#23
0
 def random(self, a):
     return math.random() * (a or 1)
示例#24
0
def stimuli():
	stimuli_list = []
  	for i in range(math.random(100,300)):
		beta = math.random(0.05, 0.15)
		n = math.random(int(10e6), int(10e8))
      	areas_list.append(Stimulus(beta, n))
示例#25
0
def areas():
  	areas_list = []
  	for i in range(math.random(100,300)):
		beta = math.random(0.05, 0.15)
		n = math.random(int(10e6), int(10e8))
      	areas_list.append(Area(beta, n, math.sqrt(n)))
示例#26
0
	return connectome(areas, stimuli)

@pytest.fixture
def areas():
  	areas_list = []
  	for i in range(math.random(100,300)):
		beta = math.random(0.05, 0.15)
		n = math.random(int(10e6), int(10e8))
      	areas_list.append(Area(beta, n, math.sqrt(n)))
    return areas_list

@pytest.fixture
def area(request):
  	beta, n, k = request.param
    if beta is None:
  		beta = math.random(0.05, 0.15)
    if n is None:
  		n = math.random(int(10e6), int(10e8))
    if k is None:
        k = math.sqrt(n)
	return Area(beta, n, k)

@pytest.fixture
def stimuli():
	stimuli_list = []
  	for i in range(math.random(100,300)):
		beta = math.random(0.05, 0.15)
		n = math.random(int(10e6), int(10e8))
      	areas_list.append(Stimulus(beta, n))
    return stimuli_list
  
import math

if (math.random() < 0.5 ):
	print("Heads")
else:
	print("Tails")
示例#28
0
 def random(self, a):
     return math.random() * (a or 1)
示例#29
0
文件: noise.py 项目: LingDong-/Hermit
	def setSeed(self,val=None):
		self.z = self.seed = (math.random()*self.m if val == None else val) >> 0
示例#30
0
def breedChild(species):
    child = []
    if math.random() < CrossoverChance:
示例#31
0
def getApiCid():
	return math.floor(1e9 * math.random())
示例#32
0
Python 3.7.1rc1 (v3.7.1rc1:2064bcf6ce, Sep 26 2018, 14:21:39) [MSC v.1914 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> import math
>>> math.fmod(37,5)
2.0
>>> 
math.random(5.0, 20.0)
Traceback (most recent call last):
  File "<pyshell#2>", line 2, in <module>
    math.random(5.0, 20.0)
AttributeError: module 'math' has no attribute 'random'
>>> import random
>>> random.random(5.0, 20.0)
Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    random.random(5.0, 20.0)
TypeError: random() takes no arguments (2 given)
>>> random.random(5.0,20.0)
Traceback (most recent call last):
  File "<pyshell#5>", line 1, in <module>
    random.random(5.0,20.0)
TypeError: random() takes no arguments (2 given)
>>> random.randint(5,20)
18
>>> 
示例#33
0
 def random_vec(self):
     vector = Quat(0, 0, 0, 0)
     while len(vector) >= 1:
         vector = 2 * Quat(0, random(), random(), random()) - Quat(0, 1, 1, 1)
     return vector
示例#34
0
def getRandomColor():
    letters = '0123456789ABCDEF'
    color = '#'
    for i in range(6):
        color += letters[math.floor(math.random() * 16)]
    return color
示例#35
0
def api(request): 
    return HttpResponse('<h1>You can find your API key here: '+ math.random(10,100)+'</h1>')