本文整理汇总了Python中random.rnd函数的典型用法代码示例。如果您正苦于以下问题:Python rnd函数的具体用法?Python rnd怎么用?Python rnd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rnd函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_target
def new_target(self):
x = self.x = rnd(600,780)
y = self.y = rnd(300,550)
r = self.r = rnd(2,50)
color = self.color = 'red'
canv.coords(self.id, x-r,y-r,x+r,y+r)
canv.itemconfig(self.id, fill = color)
示例2: readSampleXml
def readSampleXml():
counterMin = 0;
counter=int(counterMin);
counterMax = 200;
filePath = "/Users/nick/Desktop/"
fileName = "mocapData1.xml"
#trackPoint = ["l_foot","l_knee","l_hip","r_foot","r_knee","r_hip","l_hand","l_elbow","l_shoulder","r_hand","r_elbow","r_shoulder","torso","neck","head"]
trackPoint = ["head"]
scaler = 1000
xmlFile = xd.parse(filePath + "/" + fileName)
print("loaded: " + fileName)
for t in trackPoint:
polyCube()
scale(0.1,0.1,0.1)
joint = xmlFile.getElementsByTagName(t)
for j in joint:
x = scaler * float(j.getAttribute("x"))
y = scaler * float(j.getAttribute("y"))
z = scaler * float(j.getAttribute("z"))
#if(x!=0 and y!=0 and z!=0):
setFrame(counter)
counter+=1
move(x, y, z)
rotate(rnd(-1 * scaler, scaler),rnd(-1 * scaler, scaler),rnd(-1 * scaler, scaler))
keyframe()
print("...script complete.")
示例3: __init__
def __init__(self,canvas):
self.canvas = canvas
self.x = rnd(700,1000-100)
self.y = rnd(100,500)
self.r = rnd(10,50)
self.popali=0
self.id = canvas.create_oval(self.x-self.r,self.y-self.r,self.x+self.r,self.y+self.r, fill='grey')
示例4: __init__
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = image.load_image("particle").convert()
self.rect = self.image.get_rect()
self.rect.center = (rnd(0, consts.screen_size[0]), rnd(0, consts.screen_size[1]))
self.dx, self.dy = (rnd(-2, 2), rnd(-2, 2))
示例5: move
def move(self, board_size):
''' Let the player make a move
:param board_size: the size of the board (x,y)
:return: the new position or none
If the player is on the board, he goes random in one direction, then returns the new position.
If the player is not on the board, check his willingness to play and then propose a new position.
In the latter case, the player do not change his position.
'''
if self.is_placed():
while True:
direction = rnd(0, 360)
(new_x, new_y) = self.get_position()
new_x += sin(direction) * self.step
new_y += cos(direction) * self.step
if new_x < 0 or new_x > board_size[0] - 1 \
or new_y < 0 or new_y > board_size[1] - 1:
# if the coordinates are outside the board size, retry
continue
else:
self.place(new_x, new_y)
return self.get_position()
else:
# if the player is outside the board
# returns the new random coordinates if the player want to play
if rnd(1, 10) < self.willing_to_play:
return rnd(0, board_size[0] - 1), rnd(0, board_size[1] - 1)
示例6: bak_ost
def bak_ost(V, K, a):
#V - изначальное количество вершин
#K - количество вершин в кластере
#graph - генерирующийся граф
#a - притягательность вершины
graph = dok_matrix((V // K, V // K))
numbers = [0] * (V // K)
graph[0, 0] = 1
vertexs = [0, 0] + (a - 1) * [0]
for i in range(1, V):
f = rnd(1, (a + 1) * (i + 1) - 1)
if f <= a:
j = i
else:
j = vertexs[rnd(0, len(vertexs) - 1)]
vertexs.append(j)
vertexs.append(i)
graph[j // K, i // K] += 1
graph[i // K, j // K] += 1
numbers[j // K] += 1
numbers[i // K] += 1
vertexs += (a - 1) * [i]
for i in graph.keys():
graph[i[0], i[1]] /= numbers[i[0]]
return graph
示例7: __init__
def __init__(self, sirenSwitch, num=20):
self.num = num
self.sirenSwitch = sirenSwitch
self.fades = Fader(fadein=5, fadeout=30, dur=[35]*num, mul=self.sirenSwitch*.01)
self.trems = Sine(freq=[rnd(8,16) for i in range(num)], mul=.5, add=.5)
self.sines = Sine(freq=[rnd(8000, 12000) for i in range(num)], mul=self.fades*self.trems).out()
示例8: click_ball
def click_ball(event):
global scores, w, h, balls, flag_t
""" Обработчик событий мышки для игрового холста canvas
param event: событие с координатами клика
По клику мышкой нужно удалять тот объект, на который мышка указывает.
А также засчитываеть его в очки пользователя.
"""
obj = canv.find_closest(event.x, event.y)
try:
x1, y1, x2, y2 = canv.coords(obj)
radius=math.sqrt((x2-x1)**2+(y2-y1)**2)/2
# print(radius)
delta_scores=int(100/radius)
except:
x1,y1,x2,y2=0,0,0,0
if x1 <= event.x <= x2 and y1 <= event.y <= y2 and flag_t==0: # Блок на возрастание очков при времени =0
scores+=delta_scores
# print(scores)
change_scores_text()
canv.delete(obj)
# balls.remove(obj)
# Создаем новый шарик
new_ball = ball()
new_ball.x = rnd(50,w-50)
new_ball.y = rnd(50,h-50)
new_ball.r = rnd(10,50)
new_ball.nap = rnd(1,4)
new_ball.nx = 1
new_ball.ny = 1
new_ball.color = choice(['aqua', 'blue', 'fuchsia', 'green', 'maroon', 'orange',
'pink', 'purple', 'red','yellow', 'violet', 'indigo', 'chartreuse', 'lime'])
balls += [new_ball]
b.paint()
开发者ID:VasilkovaEI,项目名称:KPK2016teachers,代码行数:35,代码来源:Poimai_sharik_stop_score_and_timer_without_motion.py
示例9: __init__
def __init__(self):
# double_buffer = True, depth_size = 24
# window flip() is invoked after every on_draw() event
config = Config(double_buffer=True)
super(Window, self).__init__(resizable=True, config=config)
glClearColor(0.1,0.2,0,1)
glEnable(GL_TEXTURE_2D)
#glShadeModel(GL_SMOOTH) # TODO: what does this do?
self.keys = key.KeyStateHandler()
self.push_handlers(self.keys)
# some kind of event history
self.history={}
#self.label = pyglet.text.Label('Gebrauchswert')
#self.batch = pyglet.graphics.Batch()
#self.jaja = pyglet.sprite.Sprite(
#media.inhabitant('jaja01'), batch=self.batch)
self.clock = pyglet.clock.ClockDisplay()
#pyglet.clock.schedule_interval(self.update, 1./24)
pyglet.clock.set_fps_limit(36)
#impt = pyglet.image.SolidColorImagePattern((100,180,90,200))
#self.bg = pyglet.image.create(800,600, impt)
self.viewport = view.create(self, self.width/2,self.height/2)
#TODO: get this out of here!
j = jaja.create(world.surface.width/2,world.surface.height/2)
self.viewport.goto(map_pos(j))
self.viewport.zoom = 1.2
for i in range(25):
jaja.create(rnd(world.surface.width),rnd(world.surface.height))
示例10: add_spiders
def add_spiders(event):
global spiders
x = int(event.x)
y = int(event.y)
r = 100
for z in range(5):
spiders += [new_spider(rnd(x-r,x+r),rnd(y-r,y),15, choice(colors))]
示例11: new_game
def new_game():
global num_bombs
global num_bombs_delete
num_bombs = 0
num_bombs_delete = 3
global a
a = [[cell() for c in range(nc)] for r in range(nr)]
global bombs_count
bomb_count = 5 + rnd(25)
bombs_count = bomb_count
while bomb_count > 0:
r = rnd(nr)
c = rnd(nc)
if not a[r][c].bomb:
a[r][c].bomb = 1
bomb_count -= 1
else:
pass
for r in range(nr):
for c in range(nc):
k = 0
for dr in [-1,0,1]:
for dc in [-1,0,1]:
rr = r + dr
cc = c + dc
if rr in range(nr) and cc in range(nc):
if a[rr][cc].bomb:
k += 1
a[r][c].n = k
paint()
示例12: generarNombres
def generarNombres():
silabas = ['pan','chon','je','men','ti','ca','se']
nombre = ''
for x in range(0,rnd(2,4)):
nombre = nombre + silabas[rnd(0,len(silabas)-1)]
return nombre
示例13: inertia_weight
def inertia_weight(fi1, fi2, vel, pos, best_pos, neigh_best, weight=0.9):
new_vel = []
for idx in xrange(len(vel)):
new_vel.append(weight * vel[idx] + fi1 * rnd() * (best_pos[idx] - pos[idx]) +
fi2 * rnd() * (neigh_best[idx] - pos[idx]))
return np.array(new_vel)
示例14: bogsort
def bogsort(ls):
count = 0
while not list_sorted(ls):
count += 1
switch = (rnd(0, len(ls)-1), rnd(0, len(ls)-1))
ls[switch[0]], ls[switch[1]] = ls[switch[1]], ls[switch[0]]
print count
return ls
示例15: new_target
def new_target(self):
""" Инициализация новой цели. """
x = self.x = rnd(600,780)
y = self.y = rnd(300,550)
r = self.r = rnd(2,50)
color = self.color = 'red'
canv.coords(self.id, x-r,y-r,x+r,y+r)
canv.itemconfig(self.id, fill = color)