本文整理汇总了Python中whrandom.random函数的典型用法代码示例。如果您正苦于以下问题:Python random函数的具体用法?Python random怎么用?Python random使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了random函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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])
示例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
示例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
示例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
示例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
示例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)
示例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)
示例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
示例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)
示例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
示例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
示例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)
示例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
示例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." )
示例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()