本文整理汇总了Python中whrandom.random函数的典型用法代码示例。如果您正苦于以下问题:Python random函数的具体用法?Python random怎么用?Python random使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了random函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: randomAttackCam
def randomAttackCam(suit, toon, battle, attackDuration, openShotDuration, attackerString = 'suit'):
if openShotDuration > attackDuration:
openShotDuration = attackDuration
closeShotDuration = attackDuration - openShotDuration
if attackerString == 'suit':
attacker = suit
defender = toon
defenderString = 'toon'
else:
attacker = toon
defender = suit
defenderString = 'suit'
randomDouble = whrandom.random()
if randomDouble > 0.59999999999999998:
openShot = randomActorShot(attacker, battle, openShotDuration, attackerString)
elif randomDouble > 0.20000000000000001:
openShot = randomOverShoulderShot(suit, toon, battle, openShotDuration, focus = attackerString)
else:
openShot = randomSplitShot(attacker, defender, battle, openShotDuration)
randomDouble = whrandom.random()
if randomDouble > 0.59999999999999998:
closeShot = randomActorShot(defender, battle, closeShotDuration, defenderString)
elif randomDouble > 0.20000000000000001:
closeShot = randomOverShoulderShot(suit, toon, battle, closeShotDuration, focus = defenderString)
else:
closeShot = randomSplitShot(attacker, defender, battle, closeShotDuration)
return Track([
openShot,
closeShot])
开发者ID:Toonerz,项目名称:Toontown-2003,代码行数:30,代码来源:MovieCamera.py
示例2: vonmisesvariate
def vonmisesvariate(mu, kappa):
# mu: mean angle (in radians between 0 and 180 degrees)
# kappa: concentration parameter kappa (>= 0)
# if kappa = 0 generate uniform random angle
if kappa <= 1e-6:
return TWOPI * random()
a = 1.0 + sqrt(1.0 + 4.0 * kappa * kappa)
b = (a - sqrt(2.0 * a))/(2.0 * kappa)
r = (1.0 + b * b)/(2.0 * b)
while 1:
u1 = random()
z = cos(pi * u1)
f = (1.0 + r * z)/(r + z)
c = kappa * (r - f)
u2 = random()
if not (u2 >= c * (2.0 - c) and u2 > c * exp(1.0 - c)):
break
u3 = random()
if u3 > 0.5:
theta = mu + 0.5*acos(f)
else:
theta = mu - 0.5*acos(f)
return theta % pi
开发者ID:asottile,项目名称:ancient-pythons,代码行数:31,代码来源:random.py
示例3: dosify
def dosify(f, list):
"return a DOSified version of f that doesn't already exist in list"
flds = string.split(f, '.')
if len(flds) > 2:
flds = [string.join(flds[0:-1], '-'), flds[-1]]
elif len(flds) == 1:
flds.append('')
if len(flds[0]) > 8 or len(flds[1]) > 3:
# start with first 7 characters + last
i = 7
ext = flds[1][0:3]
base = flds[0]
newf = '%s.%s' % (base[0:i]+base[i-8:], ext)
while i and newf in list:
i = i - 1
newf = '%s.%s' % (base[0:i]+base[i-8:], ext)
# if that fails, simply use random three-digit numbers appended
# to first five characters of base name
if not i:
rnd = int(whrandom.random() * 999)
newf = '%s%03d.%s' % (base[0:5], rnd, ext)
while newf in list:
rnd = int(whrandom.random() * 999)
newf = '%s%03d.%s' % (base[0:5], rnd, ext)
return newf
return f
开发者ID:nickzuck007,项目名称:python-bits,代码行数:30,代码来源:dosnames.py
示例4: gauss
def gauss(mu, sigma):
# When x and y are two variables from [0, 1), uniformly
# distributed, then
#
# cos(2*pi*x)*sqrt(-2*log(1-y))
# sin(2*pi*x)*sqrt(-2*log(1-y))
#
# are two *independent* variables with normal distribution
# (mu = 0, sigma = 1).
# (Lambert Meertens)
# (corrected version; bug discovered by Mike Miller, fixed by LM)
# Multithreading note: When two threads call this function
# simultaneously, it is possible that they will receive the
# same return value. The window is very small though. To
# avoid this, you have to use a lock around all calls. (I
# didn't want to slow this down in the serial case by using a
# lock here.)
global gauss_next
z = gauss_next
gauss_next = None
if z is None:
x2pi = random() * TWOPI
g2rad = sqrt(-2.0 * log(1.0 - random()))
z = cos(x2pi) * g2rad
gauss_next = sin(x2pi) * g2rad
return mu + z*sigma
开发者ID:Claruarius,项目名称:stblinux-2.6.37,代码行数:31,代码来源:random.py
示例5: expovariate
def expovariate(lambd):
# lambd: rate lambd = 1/mean
# ('lambda' is a Python reserved word)
u = random()
while u <= 1e-7:
u = random()
return -log(u)/lambd
开发者ID:Claruarius,项目名称:stblinux-2.6.37,代码行数:8,代码来源:random.py
示例6: getLookAtPosition
def getLookAtPosition(self, toonHead, toonidx):
lookAtChoice = whrandom.random()
if len(self.used_panel_indexs) == 1:
lookFwdPercent = 0.33000000000000002
lookAtOthersPercent = 0
else:
lookFwdPercent = 0.20000000000000001
if len(self.used_panel_indexs) == 2:
lookAtOthersPercent = 0.40000000000000002
else:
lookAtOthersPercent = 0.65000000000000002
lookRandomPercent = 1.0 - lookFwdPercent - lookAtOthersPercent
if lookAtChoice < lookFwdPercent:
self.IsLookingAt[toonidx] = 'f'
return Vec3(0, 1.5, 0)
elif lookAtChoice < lookRandomPercent + lookFwdPercent or len(self.used_panel_indexs) == 1:
self.IsLookingAt[toonidx] = 'r'
return toonHead.getRandomForwardLookAtPoint()
else:
other_toon_idxs = []
for i in range(len(self.IsLookingAt)):
if self.IsLookingAt[i] == toonidx:
other_toon_idxs.append(i)
if len(other_toon_idxs) == 1:
IgnoreStarersPercent = 0.40000000000000002
else:
IgnoreStarersPercent = 0.20000000000000001
NoticeStarersPercent = 0.5
bStareTargetTurnsToMe = 0
if len(other_toon_idxs) == 0 or whrandom.random() < IgnoreStarersPercent:
other_toon_idxs = []
for i in self.used_panel_indexs:
if i != toonidx:
other_toon_idxs.append(i)
if whrandom.random() < NoticeStarersPercent:
bStareTargetTurnsToMe = 1
lookingAtIdx = whrandom.choice(other_toon_idxs)
if bStareTargetTurnsToMe:
self.IsLookingAt[lookingAtIdx] = toonidx
otherToonHead = None
for panel in self.panelList:
if panel.position == lookingAtIdx:
otherToonHead = panel.headModel
otherToonHead.doLookAroundToStareAt(otherToonHead, self.getLookAtToPosVec(lookingAtIdx, toonidx))
self.IsLookingAt[toonidx] = lookingAtIdx
return self.getLookAtToPosVec(toonidx, lookingAtIdx)
开发者ID:Toonerz,项目名称:Toontown-2003,代码行数:55,代码来源:AvatarChooser.py
示例7: test
def test(N):
input = vector(N)
output = vector(N)
verify = vector(N)
for i in range(N):
input[i] = whrandom.random() + 1j * whrandom.random()
unscaled_DFT (N, input, output)
unscaled_DFT (N, input, verify)
if (dump(output) != dump(verify)):
print dump(output)
print dump(verify)
开发者ID:FLYKingdom,项目名称:vlc,代码行数:14,代码来源:transforms.py
示例8: make_mtx
def make_mtx():
mat = SparseLinkMat(size, size)
if tridiagonal:
for i in range(size):
mat[i,i] = 4*whrandom.random()
if symmetric:
for i in range(0, size-1):
mat[i,i+1] = whrandom.random() - 0.5
mat[i+1,i] = mat[i,i+1]
else:
for i in range(1, size-1):
mat[i,i-1] = whrandom.random() - 0.5
mat[i,i+1] = whrandom.random() - 0.5
mat[0,1] = whrandom.random() - 0.5
mat[size-1,size-2] = whrandom.random() - 0.5
else:
for i in range(size):
if symmetric:
jval = range(i, size)
else:
jval = range(0, size)
for j in jval:
if whrandom.random() <= sparseness:
mat[i,j] = whrandom.random()
if symmetric:
mat[j,i] = mat[i,j]
return mat
开发者ID:anilkunwar,项目名称:OOF2,代码行数:27,代码来源:randommatrix.py
示例9: randomSplitShot
def randomSplitShot(suit, toon, battle, duration):
suitHeight = suit.getHeight()
toonHeight = toon.getHeight()
suitCentralPoint = suit.getPos(battle)
suitCentralPoint.setZ(suitCentralPoint.getZ() + suitHeight * 0.75)
toonCentralPoint = toon.getPos(battle)
toonCentralPoint.setZ(toonCentralPoint.getZ() + toonHeight * 0.75)
x = 9 + whrandom.random() * 2
y = -2 - whrandom.random() * 2
z = suitHeight * 0.5 + whrandom.random() * suitHeight
if MovieUtil.shotDirection == 'left':
x = -x
return focusShot(x, y, z, duration, toonCentralPoint, splitFocusPoint = suitCentralPoint)
开发者ID:Toonerz,项目名称:Toontown-2003,代码行数:14,代码来源:MovieCamera.py
示例10: _DDPlayground__seagulls
def _DDPlayground__seagulls(self, task):
if task.time < self.nextSeagullTime:
return Task.cont
base.playSfx(self.loader.seagullSound)
self.nextSeagullTime = task.time + whrandom.random() * 4.0 + 8.0
return Task.cont
开发者ID:Toonerz,项目名称:Toontown-2003,代码行数:7,代码来源:DDPlayground.py
示例11: shuffle
def shuffle(list):
pairs = []
for element in list:
pairs.append([whrandom.random(), element])
pairs.sort(first_sort)
result = map(lambda x: x[1], pairs)
return result
开发者ID:dbaaaaaarrett,项目名称:Spectmore,代码行数:7,代码来源:permute.py
示例12: makeRandom
def makeRandom(self):
"Fill the board with a random pattern"
import whrandom
self.state={}
for i in range(0, self.X):
for j in range(0, self.Y):
if whrandom.random()*10>5.0: self.set(j,i)
开发者ID:Galland,项目名称:nodebox-opengl,代码行数:7,代码来源:life.py
示例13: normalvariate
def normalvariate(mu, sigma):
# mu = mean, sigma = standard deviation
# Uses Kinderman and Monahan method. Reference: Kinderman,
# A.J. and Monahan, J.F., "Computer generation of random
# variables using the ratio of uniform deviates", ACM Trans
# Math Software, 3, (1977), pp257-260.
while 1:
u1 = random()
u2 = random()
z = NV_MAGICCONST*(u1-0.5)/u2
zz = z*z/4.0
if zz <= -log(u2):
break
return mu+z*sigma
开发者ID:Claruarius,项目名称:stblinux-2.6.37,代码行数:16,代码来源:random.py
示例14: IManageYeeshaPage
def IManageYeeshaPage(self):
vault = ptVault()
if type(vault) != type(None): #is the Vault online?
entry = vault.findChronicleEntry("VisitedGrsnPrison")
if type(entry) == type(None):
vault.addChronicleEntry("VisitedGrsnPrison",1,"yes")
PtDebugPrint ("grsnPrisonRandomItems: This is your first visit to the Prison. Updated Chronicle.")
else:
PtDebugPrint ("grsnPrisonRandomItems: You've been to the Prison before.")
chance = whrandom.random()
ageSDL = PtGetAgeSDL()
if chance > (1-kChanceOfYP):
ageSDL["grsnYeeshaPage02Vis"] = (1,)
PtDebugPrint ("grsnPrisonRandomItems: A YP is here.")
else:
ageSDL["grsnYeeshaPage02Vis"] = (0,)
PtDebugPrint ("grsnPrisonRandomItems: A YP is NOT here.")
ageSDL.sendToClients("grsnYeeshaPage02Vis")
else:
PtDebugPrint("grsnPrisonRandomItems: Error trying to access the Chronicle." )
开发者ID:Aurebesh,项目名称:moul-scripts,代码行数:27,代码来源:grsnPrisonRandomSDLItems.py
示例15: task2
def task2(ident):
global running
for i in range(numtrips):
if ident == 0:
# give it a good chance to enter the next
# barrier before the others are all out
# of the current one
delay = 0.001
else:
whmutex.acquire()
delay = whrandom.random() * numtasks
whmutex.release()
if verbose:
print 'task', ident, 'will run for', round(delay, 1), 'sec'
time.sleep(delay)
if verbose:
print 'task', ident, 'entering barrier', i
bar.enter()
if verbose:
print 'task', ident, 'leaving barrier', i
mutex.acquire()
running = running - 1
if running == 0:
done.release()
mutex.release()
开发者ID:Bail-jw,项目名称:mediacomp-jes,代码行数:25,代码来源:test_thread.py
示例16: __init__
def __init__(self, display, rect, number_of_stars, angle,
speed_sequence, size = 1, color = (255, 255, 255)):
self.display_surface = display
self.display_rect = rect
self.angle = angle
self.fastest_star_speed = speed_sequence[0]
self.slowest_star_speed = speed_sequence[1]
self.brightest_color = color
self.number_of_stars = number_of_stars
self.timer = Timer()
# create our stars
self.stars = []
for index in range(number_of_stars):
x_pos = self._random_x()
y_pos = self._random_y()
distance = whrandom.random()
speed = ((distance * \
(self.fastest_star_speed - self.slowest_star_speed)) + \
self.slowest_star_speed)
my_star = Star(x_pos, y_pos, distance, angle, speed, size, color)
self.stars.append(my_star)
开发者ID:bcherry,项目名称:bcherry,代码行数:25,代码来源:starfield.py
示例17: writerThread
def writerThread(self, d, howMany, writerNum):
name = currentThread().getName()
start = howMany * writerNum
stop = howMany * (writerNum + 1) - 1
if verbose:
print "%s: creating records %d - %d" % (name, start, stop)
# create a bunch of records
for x in xrange(start, stop):
key = '%04d' % x
dbutils.DeadlockWrap(d.put, key, self.makeData(key),
max_retries=12)
if verbose and x % 100 == 0:
print "%s: records %d - %d finished" % (name, start, x)
# do a bit or reading too
if random() <= 0.05:
for y in xrange(start, x):
key = '%04d' % x
data = dbutils.DeadlockWrap(d.get, key, max_retries=12)
self.assertEqual(data, self.makeData(key))
# flush them
try:
dbutils.DeadlockWrap(d.sync, max_retries=12)
except db.DBIncompleteError, val:
if verbose:
print "could not complete sync()..."
开发者ID:B-Rich,项目名称:breve,代码行数:29,代码来源:test_thread.py
示例18: getNewSID
def getNewSID(tag):
"""Build a new Session ID"""
t1 = time.time()
time.sleep( whrandom.random() )
t2 = time.time()
base = md5.new( tag + str(t1 +t2) )
sid = tag + '_' + base.hexdigest()
return sid
开发者ID:jacob-carrier,项目名称:code,代码行数:8,代码来源:recipe-65110.py
示例19: suitGroupThreeQuarterLeftBehindShot
def suitGroupThreeQuarterLeftBehindShot(avatar, duration):
if whrandom.random() > 0.5:
x = 12.369999999999999
h = 134.61000000000001
else:
x = -12.369999999999999
h = -134.61000000000001
return heldShot(x, 11.5, 8.1600000000000001, h, -22.699999999999999, 0, duration, 'suitGroupThreeQuarterLeftBehindShot')
开发者ID:Toonerz,项目名称:Toontown-2003,代码行数:8,代码来源:MovieCamera.py
示例20: addChild
def addChild(entryList):
import whrandom
root = entryList.entry()
n = int(root.count() * whrandom.random())
entry = root.child(n)
global _count
newEntry = Entry(text='Hello %d' % _count)
_count = _count + 1
entry.addChild(newEntry)
开发者ID:davem22101,项目名称:semanticscience,代码行数:9,代码来源:EntryList.py
注:本文中的whrandom.random函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论