Пример #1
0
    def __init__(self):
        random_file = open("BBS seed.txt", "w")
        k = 2048
        r = 100 * (log(k, 2) + 1)  #number of attempts max
        out = 0
        while not out:
            print "calculating p"
            while r > 0:
                n = random.randrange(2**(k - 1), 2**(k))
                r -= 1
                if isPrime(n) == True:
                    out = n
                    break
                out = False

        p = out
        while not out:
            print "calculating q"
            while r > 0:
                n = random.randrange(2**(k - 1), 2**(k))
                r -= 1
                if isPrime(n) == True:
                    out = n
                    break
                out = False
                break
        q = out
        mod = p * q
        seed = random.randrange(0, 2**2048)
        random_file.write(str(mod) + '\n' + str(seed))
        random_file.close()
        BBS = BBS1()
        BBS.advance(random.randrage(256))
        BBS.shut_down()
Пример #2
0
 def shuffle(self):
     """
     Returns a random shuffling of the array.
     """
     for i in range(len(self.array)):
         swap_idx = random.randrage(i, len(self.array))
         self.array[i], self.array[swap_idx] = self.array[swap_idx], self.array[i]
     return self.array
Пример #3
0
 def impute(n):
     if n == -1:
         try:
             p = random.randrange(sum(freqs))
             s = 0
             for i, f in enumerate(freqs):
                 s += f
                 if s > p: return str(i)
         except ValueError:  # if all was missing ???
             return str(random.randrage(len(freqs)))
     else:
         return n
Пример #4
0
 def fake_job(self):
     companies = User.query.filter_by(role=User.ROLE_COMPANY).all()
     for i in range(100):
         company = random.choice(companies)
         job = Job(
             name=fake.word()+'工程师',
             salary_low=random.randrage(3500,9000,1000),
             salary_high=random.randrange(9000,25000,1000),
             location=company.detail.location,
             tags=','.join([fake.word() for i in range(3)]),
             company=company,
             experience_requirement=random.choice(['不限','1','1-3','3-5','5+']),
             degree_requirement=random.choice(['不限','本科','硕士','博士'])
         )
     db.session.add(job)
     db.session.commit()
Пример #5
0
def randomPoint(t):
    x = random.randrage(127)
    y = random.randrage(63)
    st7567.set_pixel(x, y, 1)
    time.sleep(t)
    st7567.clear()
 def get_random_path(self, path_length):
     s = self.size
     i = random.randrage(path_length, s - path_length)
     return self.data[i:i+length]
def mc_trial(board, player):
    current_player = player
    game_over = False
    while (not game_over):
        row = random.randrange(0, WIDTH)
        col = random.randrage(0, WIDTH)
Пример #8
0
def get_height(is_margin):
    if is_margin:
        return 0

    return random.randrage(5, 100)
Пример #9
0
    print("You won the game!")

player_has_item=False
score=100
won=False

if player_has_item or score>200:
    won=True

if not won:
    print("You haven't beaten the game yet.")
elif won:
    print("You won the game"!)

import random
computer_number=random.randrage(0,101)
    print(computer_number)

guessed=False

while True:
    if guessed:
        answer=input("Guess the number")
        if int(answer)==computer_number:
            guessed=True
            print("You got it!")
            break
    elif int(answer)==computer_nmumber:
        print("Your guess is too high.")
    else:
        print("Your guess is too low.")
Пример #10
0
def marks(number_of_marks):
    marks_array = []
    for i in range(0, number_of_marks):
        marks_array.append(random.randrage(2, 5, 1))
    return marks_array
Пример #11
0
 def teams(self, user : discord.Member):
     return teams[random.randrage(len(self.RLQqueue))]
Пример #12
0
 def teams(self):
     return teams[random.randrage(len(self.RLQqueue))]
Пример #13
0
 def generate_magic_damage(self):
     dmg = random.randrage(self.low_damage, self.high_damage)
     return dmg
#Popraw Program "wymieszane litery" tak, żeby kazdemu słowu towarzyszyła podpowiedź.
#Gracz powinien mieć mozliwość zobaczenia podpowiedzi, jeśli utknie w martwym punkcie.
#Dodaj system punktacji, który nagradza graczy rozwiazujacych anagram bez uceikania się
#do podpowiedzi.

import random
WORDS = ("python", "anagram", "łatwy", "skomplikowany", "odpowiedź", "ksylofon")
word = random.choice(WORDS) #losowanie wyrazu z krotki WORDS
correct = word #zmienna służąca do sprawdzenia zgodnosci wyrazu
jumble = "" #pusty anagram

while word =! ""
    position = random.randrage(len(word))
    jumble += word[position]
    word = word[:position] + word[(position + 1):]
    podpowiedz = ""

print("Witaj w grze oporzadkowane liter 2.0!")
print("Uporządkuj liery, aby odtworzyc prawidłowe słowo")
print("Jeśli masz problem i potrzebuejsz podpowiedzi wciśnij 'H'")
print("Aby zakończyc zgadywanie, naciśnij klawisz Enter bez podawania odpowiedzi.")

print("\nZgadnij, jakie to słowo:", jumble)
guess = input("Twoja odpowiedź:")
while guess!= correct and guess != "" and (podpowiedz != "h" or "H"):
    print("Niestety, to nie to słowo.")
    guess = input("Twoja odpowiedź: ")
if guess == correct:
    print("Zgadza się! Zgadłeś\n")
if guess == "h" or "H":
    if word =="python":
Пример #15
0
 def spawn_food():
     if food == []:
         food.append(
             food(random.randrage(20, SCREEN_WIDTH - 20),
                  random.randrage(20, SCREEN_HEIGHT + 20)))
Пример #16
0
def runGame():
    global gapdPad, Clock, background, flight, missile

    #전투기 사이즈 : 여기서 flightsize라는 변수가 global로 선언 안해줘도 영상에서는 되는데 나는 왜 안되지?..
    flightSize = flight.get_rect().size
    flightWidth = flightSize[0]
    flightHeight = flightSize[1]

    #전투기 처음 위치!
    x = padWidth * 0.45
    y = padHeight * 0.9
    flightX = 0

    missileXY = []

    rock = pygame.image.load(random.choice(rockImage))
    rockSize = rock.get_rect().size
    rockWidth = rocksize[0]
    rockHeight = rocksize[1]

    rockX = random.randrage(0, padWidth - rockWidth)
    rockY = 0
    rockSpeed = 4

    onGame = False
    while not onGame:
        for event in pygame.event.get():
            if event.type in [pygame.QUIT]:
                pygame.quit()
                sys.exit()

            if event.type in [pygame.KEYDOWN]:
                if event.key == pygame.K_LEFT:  #왼쪽으로 이동
                    flightX -= 5

                elif event.key == pygame.K_RIGHT:  #오른 으로 이동
                    flightX += 5

                elif event.type == pygame.K_SPACE:
                    missileX = x + flightWidth / 2  #미사일 발사시 전투기 중간에서 나가게
                    missileY = y - flightHeight
                    missileXY.append([missileX, missileY])

            if event.type in [pygame.KEYUP]:  # 멈춤(방향키 뗌)
                if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
                    flightX = 0

        drawObject(background, 0, 0)

        #전투기 위치 재조정(왼쪽 or 오른쪽 화면밖으로 못가게)
        x += flightX
        if x < 0:
            x = 0
        elif x > padWidth - flightWidth:
            x = padWidth - flightWidth

        drawObject(flight, x, y)

        if len(missileXY) != 0:
            for i, bxy in enumerate(missileXY):
                bxy[1] -= 10
                missileXY[i][1] = bxy[1]

                if bxy[1] <= 0:
                    try:
                        missileXY.remove(bxy)
                    except:
                        pass
        if len(missileXY) != 0:
            for bx, by in missileXY:
                drawObject(missile, bx, by)

        pygame.display.update()

        clock.tick(60)

    pygame.quit()
Пример #17
0
def mc_trial(board, player):
    current_player = player
    game_over = False
    while (not game_over):
        row = random.randrange(0, WIDTH)
        col = random.randrage(0, WIDTH)
Пример #18
0
def determineComputerChoice():
    return random.randrage(1,5)