コード例 #1
0
    def metropolis_transfer(self, beta, Box, factor):
        n = int(self.N * ran())
        x = self.r[n][0]
        y = self.r[n][1]

        drx = dr * (2 * ran() - 1)
        dry = dr * (2 * ran() - 1)

        x_new = x + drx
        y_new = y + dry

        if x_new < 0: x_new += Box.L
        elif x_new > Box.L: x_new -= Box.L

        if y_new < 0: y_new += Box.L
        if y_new > Box.L: y_new -= Box.L

        dE = Box.calculate_energy(n, x_new, y_new) - self.calculate_energy(
            n, x, y)

        if dE <= 0:
            Box.r.append([x_new, y_new])
            self.r.pop(n)
            self.N = len(self.r)
        elif ran() < factor * m.exp(-beta * dE):
            Box.r.append([x_new, y_new])
            self.r.pop(n)
            self.N = len(self.r)
コード例 #2
0
def getInput():
    global totalDots
    global insideDots
    userInput = int(entryPrecision.get())
    count = 0
    radius = float(((size - 20) / 2))
    while count <= userInput:
        x, y = (ran(10, size - 10), ran(10, size - 10))
        dist = ((((radius - x)**2) + ((radius - y)**2))**(1 / 2))
        canvas.create_oval(x, y, x, y, width=1, outline='white')
        count += 1
        totalDots += 1
        if dist <= radius:
            insideDots.append(1)
        canvas.update()
    canvas.create_oval(10, 10, size - 10, size - 10, width=5, outline='black')
    canvas.create_oval(10,
                       10,
                       size - 10,
                       size - 10,
                       width=3,
                       outline='#38d14f')
    pi = 4 * (len(insideDots) / totalDots)
    piDisplay = Label(text=pi)
    piDisplay.pack(side=BOTTOM)
コード例 #3
0
    def metropolis_translation(self, beta):
        n = int(self.N * ran())
        x = self.r[n][0]
        y = self.r[n][1]

        drx = dr * (2 * ran() - 1)
        dry = dr * (2 * ran() - 1)

        x_new = x + drx
        y_new = y + dry

        if x_new < 0: x_new += self.L
        elif x_new > self.L: x_new -= self.L

        if y_new < 0: y_new += self.L
        if y_new > self.L: y_new -= self.L

        dE = self.calculate_energy(n, x_new, y_new) - self.calculate_energy(
            n, x, y)

        if dE <= 0:
            self.r[n][0] = x_new
            self.r[n][1] = y_new
        elif ran() < m.exp(-beta * dE):
            self.r[n][0] = x_new
            self.r[n][1] = y_new
コード例 #4
0
 def gen_str(msh):
     str = ['' for _ in range(9)]
     for x in range(8, 3, -1):
         digit = ran(0, x)
         while str[digit] != '':
             digit += 1
         str[digit] = msh.pp(ran(0, len(msh) - 1))
     return str
コード例 #5
0
def getting_food(snake, box):
    food = None
    while food is None:
        # random position between [Upper Y + 1 , Lower Y - 1], [Left X + 1, Right X - 1]
        food = [ran(box[0][0] + 1, box[1][0] - 1), ran(box[0][1] + 1, box[1][1] - 1)]
        if food in snake:
            food = None
    return food
コード例 #6
0
def gaussianRand(mu, sigma):
    """ Two independent uniformly distributed random variables xi1 and xi2 become 
	two independent Gaussian distributed variables Xf and Yf under Box-Müller 
	Transformation.
	"""
    xi1, xi2 = ran(), ran()
    Xf, Yf = sqrt(-2 * log(xi1)) * cos(2 * pi * xi2), sqrt(
        -2 * log(xi1)) * sin(2 * pi * xi2)
    return (mu + sigma * Xf)
コード例 #7
0
 def addBomb(self, h: int, w: int, b: int):
     if b > h * w:
         exit(1)
     for i in range(b):
         hran = round(ran() * (h - 1))
         wran = round(ran() * (w - 1))
         while self.mine[hran][wran]:
             hran = round(ran() * (h - 1))
             wran = round(ran() * (w - 1))
         self.mine[hran][wran] = True
コード例 #8
0
ファイル: Zibil.py プロジェクト: gnorayr/infa_2020_Gevorgyan
 def __init__(self, bottom=GROUND_Y, top=0, left=0, right=SCREEN_X):
     self.color = RED
     self.r = ran(20, 25)
     self.right = right
     self.left = left
     self.top = top
     self.bottom = bottom
     self.x = ran(self.left + self.r, self.right - self.r)
     self.y = ran(self.top + self.r, self.bottom - self.r)
     self.v = self.r / 4
     self.angle = ran(0, int(2 * pi * 100))
     self.vx = self.v * cos(self.angle // 100)
     self.vy = self.v * sin(self.angle // 100)
コード例 #9
0
ファイル: Masr.py プロジェクト: TEAMRAMIS/m
def home():
    for x in range(300):
        if s == '010':
            f = str(ran(101111111, 109999999))
        else:
            if s == '011':
                f = str(ran(111111111, 119999999))
            else:
                if s == '012':
                    f = str(ran(121111111, 129999999))
                else:
                    if s == '015':
                        f = str(ran(151111111, 159999999))
                    else:
                        exit()
        login = '******'
        useragents = [(
            'Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 .Firefox/45.0',
            'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1'
        )]

        def Cr():
            br = mechanize.Browser()
            cj = cookielib.LWPCookieJar()
            br.set_handle_robots(False)
            br.set_handle_redirect(True)
            br.set_cookiejar(cj)
            br.set_handle_equiv(True)
            br.set_handle_referer(True)
            br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(),
                                  max_time=1)
            br.addheaders = [('User-agent', random.choice(useragents))]
            site = br.open(login)
            br.select_form(nr=0)
            br.form['email'] = '0' + f
            br.form['pass'] = '******' + f
            sub = br.submit()
            log = sub.geturl()
            print(A5thar)
            print 'Loiding On The Accounts...' '0' + f
            if log != login and 'login_attempt' not in log:
                print(Roz)
                print 'Accounts is  Checking'
            else:
                print(A7mar)
                print 'Accounts not checking'

        Cr()
コード例 #10
0
ファイル: soundt.py プロジェクト: orcapt/orca_python
def A(a1,a2,a3,a,b,c,d,e):
    aas=[a1,a2,a3]
    oos=[a,b,c,d,e]
    choiceA=[]
    for elem in range(ran(2,7)):
        choiceA.append([choice(aas),choice(oos)])
    return(choiceA)
コード例 #11
0
def RPS:
    hands = ["R","P","S",
]
    Win = 0
    Los = 0
    Tie = 0
    print("q to leave")
    while True:
        person_rps = input("Witch one? Rock Paper or Scissors(R/P/S)")
        if person_rps.upper() == "Q":
            break
        elif person_rps.upper() in hands:
            computer_rps = str(hands[ran(1,3)-1])
            print(computer_rps)
            if computer_rps.upper() == person_rps.upper():
                print ("Tie")
                Tie += 1
            elif hands[position(hands,computer_rps)-1] == person_rps.upper():
                print("Los")
                Los+ = 1
            else:
                Win += 1 
        else:
            print("Cheaters loose")
    print("Wins : %s, Losses: %s, Ties %s." % (Win Los,Tie))
コード例 #12
0
def noise():
    global img, way
    way = input()
    way = 'Загруженные фотографии/' + way
    print('Оцените мощность шумов от 0 до 100')
    power = int(input())
    if power < 0 or power > 100:
        print('Вы ввели недопустимое значение')
        menu()
    img = Image.open(way)
    img = img.convert(mode="RGBA")
    pixels = img.load()
    i = 0
    while i < img.width:
        j = 0
        while j < img.height:
            r, g, b, a = pixels[i, j]
            c = ran(0, round(power * 2.55))
            r += c % 255
            g += c % 255
            b += c % 255
            a += c % 255
            pixels[i, j] = (r, g, b, a)
            j = j + 1
        i = i + 1
    img.show()
コード例 #13
0
def rockPaperScissors():
    com = ran(0, 2)
    gamerChoice = input('Pick Rock Paper or Scissors: \n')
    comStr = ['Rock', 'Paper', 'Scissors']
    epic = comStr[com]
    if gamerChoice == epic:
        print('They Chose {}!'.format(epic))
        q = input('Tie \nReplay? y/n: ')
        if q == 'y':
            rockPaperScissors()
        else:
            quit
    if gamerChoice == 'Rock':
        if epic == 'Scissors':
            q = input('You Win! \nReplay? y/n: ')
            if q == 'y':
                rockPaperScissors()
            else:
                quit
        elif epic == 'Paper':
            print('They Chose {}!'.format(epic))
            q = input('You Lose! \nReplay? y/n: ')
            if q == 'y':
                rockPaperScissors()
            else:
                quit
    elif gamerChoice == 'Paper':
        if epic == 'Rock':
            q = input('You Win! \nReplay? y/n: ')
            if q == 'y':
                rockPaperScissors()
            else:
                quit
        elif epic == 'Scissors':
            print('They Chose {}!'.format(epic))
            q = input('You Lose! \nReplay? y/n: ')
            if q == 'y':
                rockPaperScissors()
            else:
                quit
    elif gamerChoice == 'Scissors':
        if epic == 'Rock':
            print('They Chose {}!'.format(epic))
            q = input('You Lose! \nReplay? y/n: ')
            if q == 'n':
                rockPaperScissors()
            else:
                quit
        elif epic == 'Paper':
            q = input('You Win! \nReplay? y/n: ')
            if q == 'y':
                rockPaperScissors()
            else:
                quit
    else:
        q = input('Invalid Choice \n Replay? y/n: ')
        if q == 'y':
            rockPaperScissors()
        else:
            quit
コード例 #14
0
def encrypt(txt):
    file = open('dict.py').readlines()
    ls = []
    for i in range(len(file)):
        ls.append(file[i].strip('\n'))
    txt = list(txt)
    inpt = []
    for i in txt:
        try:
            inpt.append(ls.index(i) + 1)
        except Exception as e:
            pass
    txts = []
    txtz = []
    for i in range(10):
        txtz.append(ls[ran(0, len(ls) - 1)])
    txtv = 0
    for i in range(10):
        if i == 0:
            txtv = ls.index(txtz[i])
        else:
            txtv += ls.index(txtz[i])
    n = txtv
    total = 0
    for ii, i in enumerate(inpt):
        if ii == 0:
            total += i
        else:
            iss = i
            if len(str(i)) == 1:
                iss = '0' + str(iss)
            total = int(str(total) + str(iss))
    total *= n
    total *= n
    return [''.join(txtz), total]
コード例 #15
0
    def Attack(self):
        print(self.name + " saldırıyor.")
        spent_bullets = ran(0, 10)
        print(str(spent_bullets) + " mermi harcandı")
        self.bullet_count -= spent_bullets

        return spent_bullets, self.fight_power
コード例 #16
0
def RPSLSp():
    hands = ["R","SP","P","L","S",]
    Win = 0
    Los = 0
    Tie = 0
    print("q to leave")
    while True:
        person_rps = input("Which one? Rock, Paper, Scissors, Lizard, or Spock? (R/P/S/L/SP)")
        if person_rps.upper() == "Q":
        break
        elif person_rps.upper() in hands:
            computer_rps = str(hands[ran(1,5)-1])
            print computer_rps
            if computer_rps.upper() == person_rps.upper():
                print ("Tie")
                Tie += 1
            elif hands[position(hands,computer_rps)-1] == person_rps.upper() or hands[position(hands,computer_rps)-2] == person_rps.upper():
                print("Lose")
                Los += 1
            else:
                Win += 1
                print("Win")
        else:
            print("Cheaters loose")
    print("Wins : %s, Losses: %s, Ties %s." % (Win,Los,Tie))
コード例 #17
0
ファイル: main.py プロジェクト: ahmadabdulnasir/imeisender
def notgen(n, imei):
    array = []
    physics = list(range(0, n))
    for i in physics:
        check = str(ran(0, 9))
        imeic = str(imei + i) + check
        array.append(imeic)
    return array
コード例 #18
0
def Ising(S, beta, steps) : 
    for sweep in range(steps) : 
        for i in range(vol) :
            k = randint(0, vol-1)
            h = S[nbhr(k)[0]] + S[nbhr(k)[1]] + S[nbhr(k)[2]] + S[nbhr(k)[3]]
            dE = 2*h*S[k]
            boltzmann = np.exp(-beta*dE)
            if ran(0., 1.) < boltzmann : S[k] = -S[k]
    return S 
コード例 #19
0
def genSerial():
    dserial = ''
    now = datetime.now()
    dserial += str(now.day)
    dserial += str(now.year)
    dserial += str(now.month)
    dserial += str(now.second)
    serial = int(dserial[::-1])+ran(1995,2018)
    return str(serial)
コード例 #20
0
def Ising(S, beta, steps):
    for sweep in range(steps):
        for i in range(vol):
            k = randint(0, vol - 1)
            h = sum(S[nbhr(k)[j]] for j in range(4))
            dE = 2 * h * S[k]
            boltzmann = np.exp(-beta * dE)
            if ran(0., 1.) < boltzmann: S[k] = -S[k]
    return S
コード例 #21
0
def generaBalaEnemigo(listaEnemigos,listaBalasEnemigos, imgBala):
    while len(listaEnemigos) > 1:
        disparo = listaEnemigos[ran(0, len(listaEnemigos))]
        spriteBala = pygame.sprite.Sprite()
        spriteBala.image = imgBala
        spriteBala.rect = imgBala.get_rect()
        spriteBala.rect.top = disparo.rect.top + disparo.rect.height
        spriteBala.rect.left = disparo.rect.left + (disparo.rect.width // 2)
        listaBalasEnemigos.append(spriteBala)
コード例 #22
0
 def MCmove(self, beta):
     ''' This is to execute the Monte Carlo moves using 
     Metropolis algorithm such that detailed
     balance condition is satisified'''
     for k in range(vol) :
         h = sum(config[self.nbhr(k)[j]] for j in range(4))
         dE = 2*h*config[k]
         boltzmann = np.exp(-beta*dE)
         if ran(0., 1.) < boltzmann : config[k] = -config[k]
     return config
コード例 #23
0
 def selecionaPai(self, somatotal):
     pai = -1
     valor_sorteado = ran() * somatotal
     soma = 0
     i = 0
     while i < len(self.populacao) and soma < valor_sorteado:
         soma += self.populacao[i].nota_avaliacao
         pai+=1
         i+=1
     return pai
コード例 #24
0
ファイル: Functions.py プロジェクト: mannion9/nTOF-Simulation
def DiscreteChoice(events):
    ''' Events is a list of the form [0,...information...,0]. So that information is the information about the weighting of each event you consider '''
    ep = ran()
    middle = ep*sum(events)
    index = 1
    for index in range(len(events)):    
        left  = sum(events[0:index])
        right = left + events[index] #sum(events[0:index+1])
        if (left < middle <= right) == True:
            return(index-1)
コード例 #25
0
 def mutacao(self, taxa_mutacao):
    # print ("Antes %s" %self.cromossomo)
     for i in range (len(self.cromossomo)):
         if ran() < taxa_mutacao:
             if self.cromossomo[i] == "1":
                 self.cromossomo[i] = "0"
             else:
                 self.cromossomo[i] = "1"
    # print ("Depois %s" %self.cromossomo)
     return self
コード例 #26
0
 def remove(self):  # zwraca losowy element
     if self.is_empty():
         raise IndexError("Z pustego i Salomon nie naleje")
     else:
         x = ran(self.head, self.tail - 1)
         item = self.items[x]
         self.items[x] = self.items[self.head]
         self.items[self.head] = None
         self.head = (self.head + 1) % self.n
         return item
コード例 #27
0
def genPin():
    dpin = ''
#    sp = '-'
    now = datetime.now()
    dpin = str(now.microsecond)
    dpin += str(now.minute)
    salt = ran(1995,2018)
    dpin += str(now.hour+salt)
    #dpin += str(in))
    pin = dpin[::-1]
    return pin
コード例 #28
0
    def volume_change_utilities(self, id):
        dV = self.L2 * ran() * 0.001
        V_new = self.L2 + id * dV
        change = (V_new / self.L2)**(1 / 3)
        temp = self.r

        for r in temp:
            r[0] *= change
            r[1] *= change

        return (self.calculate_energy(-1, 0, 0), dV, change)
コード例 #29
0
def calcularPi():
    canvas.delete('all')

    # Variáveis
    raio = tamanho/2
    pontoDentro = 0
    pontoTotal = 0

    # Círculo
    circulo = canvas.create_oval(0, 0, tamanho, tamanho, outline='#7d0101', width=2)

    # Loop
    inputUsuario = nPontos.get()
    for i in range(int(inputUsuario)):

        # Gerar coordenadas
        coordx = ran(0, tamanho)
        coordy = ran(0, tamanho)

        # Mostrar pontos
        canvas.create_oval(coordx, coordy, coordx, coordy, outline='#bdc1c9', width=2)

        # Checar onde caiu
        dist = ((raio - coordx)**2 + (raio - coordy)**2)**0.5
        pontoTotal += 1
        if dist <= raio:
            pontoDentro += 1

        # Calcular pi
        pi = 4*pontoDentro/pontoTotal

        # Exibir valor
        display.config(text='{:.5f}'.format(pi))
        sleep(0.01)
        canvas.update()

    canvas.itemconfig(circulo, outline='#75a158')
コード例 #30
0
ファイル: enemy.py プロジェクト: elgrandt/TuxWorld-2
 def __init__(self,X,Y,NAME,TYPE,mobile=True,direccion = "Random", limite0 = -10000, limite1 = -10000,limite2 = 10000, limite3 = 10000):
     TYPE = int(TYPE)
     self.mobile = mobile
     self.angle = ran(0,360)
     self._TYPE = TYPE
     self.direccion = direccion
     self.dirh = 1
     self.dirv = 1
     self.limites = [limite0, limite1, limite2, limite3]
     if TYPE == 1:
         self.type1()
     elif TYPE == 2:
         self.type2()
     tags = ["Enemy","Wall","Mobile"]
     self.element(X, Y, NAME, "Enemy", tags, self.surface)
コード例 #31
0
 def __init__(self, espacos, valores, limite_espacos, geracao = 0):
     self.espacos = espacos
     self.valores = valores
     self.limite_espacos = limite_espacos
     self.nota_avaliacao = 0
     self.espaco_usado = 0
     self.geracao = geracao
     self.cromossomo = []
     
     #Criando individuo aleatoriamente. NADA DE INTELIGENCIA, AINDA
     for i in range (len(espacos)):
         if ran() < 0.5:
             self.cromossomo.append("0")
         else:
             self.cromossomo.append("1")
コード例 #32
0
ファイル: main.py プロジェクト: gitter-badger/QOTD
 def main_func(self):
     os.chdir("/home/jakesyl/Quotes/pyQOTD/src/")
     response = urlopen('http://www.iheartquotes.com/api/v1/random')
     html = response.read()
     filename = str(strftime("%Y-%m-%d", gmtime()))
     filename += str(ran(90))
     filename += '.md'
     with open(filename, mode = 'a', encoding = 'utf-8') as a_file:
         a_file.write(str(html))
     gitpush = sp.check_output('git add -A && git pull && git commit -m "daily file" && git push -f', stderr=sp.STDOUT, shell=True)
     gitpush
     commands = ["mv " + filename +  ' ~/Quotes/QOTD/_posts/', 'cd ~/Quotes/QOTD/ && git add -A',  'cd ~/Quotes/QOTD/ && git commit -m "added new posts"',  'cd ~/Quotes/QOTD/ && git pull', 'cd ~/Quotes/QOTD/ &&  git push -f', 'cd ~/Quotes/pyQOTD/ && rm -rf ' + filename +  ' && git add -A && git pull && git commit -m "added daily file" && echo hi && git push -f && echo done']
     for command in commands:
      gitpush = sp.check_output(command , stderr=sp.STDOUT, shell=True)
      gitpush
コード例 #33
0
def executeRandom(command, PATH2IMAGES, TIME2WAIT, stop):  # Script execution: Random
    pic = []
    while True:
        array = listdir(PATH2IMAGES)

        if stop > len(array):
            stop = len(array)

        for i in range(stop):
            pic.append(array.pop(ran(0, len(array) - 1)))

        array = None

        for i in range(stop):
            # print("Pic: >>>"+pic[0]+"<<<")
            system(command + PATH2IMAGES + renamePic(pic.pop(0)))
            sleep(TIME2WAIT)
コード例 #34
0
 def crossover(self, individuo):
     ##Calcula o corte (de um ponto) aleatoriamente
     corte = round(ran() * len(self.cromossomo))
     
     ##Cria os CROMOSSOMOS dos filhos a partir do corte criado
     filho1 = individuo.cromossomo[0:corte] + self.cromossomo[corte::]
     filho2 = self.cromossomo[0:corte] + individuo.cromossomo[corte::]
     
     ##cria os individuos filho
     filhos = [Individuo(self.espacos, self.valores, self.limite_espacos, self.geracao + 1),
               Individuo(self.espacos, self.valores, self.limite_espacos, self.geracao + 1)]
     
     ##Necessário setar o cromossomo para esses filhos
     filhos[0].cromossomo = filho1
     filhos[1].cromossomo = filho2
     
     return filhos
コード例 #35
0
    def insertData(self):
        users = list()
        for x in range(0, 50, 1):
            users.append((ran(1,5), ran(40, 60), ran(5,10), ran(70401, 70406), self.random_date()))
            users.append((ran(1,5), ran(0, 20), ran(5,10), ran(70406, 70410), self.random_date()))
            users.append((ran(1,5), ran(80, 90), ran(5,10), ran(70410, 70415), self.random_date()))


        self.c.executemany('INSERT INTO "%s" (Type, Amount, Category,zipcode, datetime) VALUES(?,?,?,?, ?)'%self.tableName, users)
        self.conn.commit()
        return "success"
コード例 #36
0
ファイル: soundt.py プロジェクト: orcapt/orca_python
# -*- coding: utf-8 -*-
"""
Created on Wed Aug 31 18:37:48 2016

@author: SRINIVAS
"""

import winsound
from random import randint as ran
from random import choice
winsound.Beep(6000, 100)
a=ran(200,1000)
b=ran(200,1000)
c=ran(200,1000)
d=a=ran(100,500)
e=a=ran(200,1000)
a1=ran(100,500)
a2=ran(100,3000)
a3=ran(100,3000)
b1=[]
choiceA=[]
choiceB=[]
choiceC=[]
def A(a1,a2,a3,a,b,c,d,e):
    aas=[a1,a2,a3]
    oos=[a,b,c,d,e]
    choiceA=[]
    for elem in range(ran(2,7)):
        choiceA.append([choice(aas),choice(oos)])
    return(choiceA)
At=A(a1,a2,a3,a,b,c,d,e)
コード例 #37
0
from sklearn.datasets.samples_generator import make_blobs


tablep ="Transaction"
countQuery=' SELECT rowid, * FROM "%s"' %tablep
deleteQuery=' DELETE FROM "%s" where Amount = 0' %tablep
selectAmountQuery=' SELECT AMOUNT FROM "%s"' %tablep
conn = sql.connect('History')
print("connection successful")
c = conn.cursor()


#c.execute(countQuery)
users = list()
for x in range(0, 10, 1):
    users.append((0, ran(210, 240), "", ran(70401, 70406), "", ""))
#c.executemany('INSERT INTO "%s" (Type, Amount, Category,zipcode, date,time) VALUES(?,?,?,?,?,?)'%tablep, users)
conn.commit()

def insert(type, amount, category, zipcode, date, time):
    c.execute('INSERT INTO "Transaction" (Type, Amount, Category,zipcode, date,time) VALUES(?,?,?,?,?,?)', type, amount, category, zipcode, date, time)



amount=list()
for row in c.execute(countQuery):
    print (row),
    amount.append(float(row[0]))


X=StandardScaler().fit_transform(amount)
コード例 #38
0
ファイル: Functions.py プロジェクト: mannion9/nTOF-Simulation
def Choice(cdf,x):
    ''' Inputs: cdf [type = list or vector], x values [type=list or vector]; Output: floating point value of choice '''
    ''' Returns the the chosen value (corresponding to the CDF) that are closest to the choice random value (ranging from 0 to 1)'''
    choice = ran()
    return interpol(choice,cdf,x,option='linear')
コード例 #39
0
ファイル: packing.py プロジェクト: lgarcin/TIPE
import matplotlib.pyplot as plt
import matplotlib.animation as animation

L = [(0.25, 0.25), (0.75, 0.25), (0.25, 0.75), (0.75, 0.75)]
sigma = 0.15
delta = 0.15
square_x = [0, 1, 1, 0, 0];
square_y = [0, 0, 1, 1, 0]
number = 0

fig = plt.figure()
ims = []
for iter in range(100):
    a = choice(L)
    L.remove(a)
    b = (a[0] + ran(-delta, delta), a[1] + ran(-delta, delta))
    min_dist = min((b[0] - x[0]) ** 2 + (b[1] - x[1]) ** 2 for x in L)
    box_cond = min(b[0], b[1]) < sigma or max(b[0], b[1]) > 1 - sigma
    if box_cond or min_dist < 4 * sigma ** 2:
        L.append(a)
    else:
        L.append(b)
    if iter % 1 == 0:
        number += 1
        plt.axes()
        for x, y in L:
            cir = plt.Circle((x, y), radius=sigma, fc='r')
            plt.gca().add_patch(cir)
        plt.axis('equal')
        ims.append((plt.plot(square_x, square_y),))