本文整理汇总了Python中whrandom.randint函数的典型用法代码示例。如果您正苦于以下问题:Python randint函数的具体用法?Python randint怎么用?Python randint使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了randint函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: GetRandomName
def GetRandomName(self):
"Build a random name from random numbers"
fname = whrandom.randint(NAME_LOWER_BOUND, NAME_UPPER_BOUND)
lname = whrandom.randint(NAME_LOWER_BOUND, NAME_UPPER_BOUND)
name = ` fname ` + " " + ` lname ` + ` lname `
return name
开发者ID:aevernon,项目名称:triggerman,代码行数:7,代码来源:data_stress_test.py
示例2: InitNewSDLVars
def InitNewSDLVars(self):
ageSDL = PtGetAgeSDL()
ageSDL["UrwinLastUpdated"] = (PtGetDniTime(),)
beginningOfToday = PtGetDniTime() - int(PtGetAgeTimeOfDayPercent() * kDayLengthInSeconds)
endOfToday = int(kDayLengthInSeconds / 2) + beginningOfToday
#print "Dawn: %d Dusk: %d" % (beginningOfToday, endOfToday)
# We need a random times in the first 5 hours of the day
# which is in the first 44.5 percent of the day. So we're
# generating a number from 0 to 445 and dividing by 1000 to get
# something roughly in that timeframe.
randnum = float(whrandom.randint(0,kFirstMorningSpawn))
firstTime = int((randnum / 1000.0) * kDayLengthInSeconds) + beginningOfToday
print "nglnUrwinBrain: Generated a valid spawn time: %d" % (firstTime)
spawnTimes = [firstTime]
while type(spawnTimes[-1]) == type(long(1)):
randnum = whrandom.randint(kMinimumTimeBetweenSpawns, kMaximumTimeBetweenSpawns)
newTime = spawnTimes[-1] + randnum
if newTime < endOfToday:
print "nglnUrwinBrain: Generated a valid spawn time: %d" % (newTime)
spawnTimes.append(newTime)
else:
print "nglnUrwinBrain: Generated a spawn time after dusk, exiting loop: %d" % (newTime)
break
else:
print "nglnUrwinBrain:ERROR---Tried to add a spawn time that's not a number: " , spawnTimes
spawnTimes = [0]
while len(spawnTimes) < 20:
spawnTimes.append(0)
ageSDL["UrwinSpawnTimes"] = tuple(spawnTimes)
开发者ID:Aurebesh,项目名称:moul-scripts,代码行数:35,代码来源:nglnUrwinBrain.py
示例3: unregister
def unregister(self):
i = whrandom.randint(0, len(self.np)-1)
r = whrandom.randint(0, (self.np[i].num_notices)-1)
#while (not self.np[i].notice_names_flgs[r]):
#search for a registered notice
#i = whrandom.randint(0, len(self.np)-1)
#r = whrandom.randint(0, (self.np[i].num_notices)-1)
name_str = self.np[i].notice_names[r]
lock1.acquire()
print "REPORTER "+self.id+": unregister notice "+name_str
timestamp = time.time()
#self.notice_sess.unregister_notice(name_str)
self.conn.unregister_notice(name_str)
#check if we were currently registered for this notification
if self.np_stats.notice_names_flgs[i][r] == 1:
#flag notice as NOT registered for
self.np_stats.notice_names_flgs[i][r] = 0
#record stop time
self.np_stats.notice_names_intervals[i][r][1] = timestamp
#write notice_name and start and stop times to log file
self.file_ptr.write('"'+name_str+'", '+`self.np_stats.notice_names_intervals[i][r][0]`+', '+`timestamp`+'\n')
lock1.release()
开发者ID:aevernon,项目名称:triggerman,代码行数:31,代码来源:newsroom.py
示例4: fillscreen
def fillscreen(im):
(maxx,maxy)=im.size
for y in xrange(maxy):
print y
for x in xrange(maxx):
if pointwhite(im,x,y):
color=(whrandom.randint(1,255),whrandom.randint(1,255),whrandom.randint(1,255))
floodfill(im,x,y,color)
开发者ID:dcrasch,项目名称:tfp,代码行数:8,代码来源:pytessel.py
示例5: ShroomieSurfaces
def ShroomieSurfaces(self,spawn):
ageSDL = PtGetAgeSDL()
respVisible.run(self.key)
if spawn == 1: # it was the lever pull which attracted Shroomie
tldnMainPowerOn = ageSDL["tldnMainPowerOn"][0]
whichbehavior = whrandom.randint(1,4)
if tldnMainPowerOn:
print "tldnShroomieBrain: The Power Tower noise has scared Shroomie. He'll come, but not very close."
NearOrFar = "Far"
else: #Determine how far out Shroomie will be seen. Added 12/12/2004
print "tldnShroomieBrain: The Power Tower is down, so Shroomie isn't scared by the noise."
howclose = whrandom.randint(1,100)
if howclose == 1:
NearOrFar = "Near"
elif howclose > 1 and howclose < 50:
NearOrFar = "Mid"
elif howclose >= 50:
NearOrFar = "Far"
else: # it was entering a shoreside zone that attracted Shroomie
whichbehavior = whrandom.randint(2,4)
NearOrFar = "Far"
print "tldnShroomieBrain: whichbehavior = ",whichbehavior," NearOrFar = ",NearOrFar
whichspawnpoint = whrandom.randint(1,5)
if NearOrFar == "Near":
code = "target = SpawnNear0" + str(whichspawnpoint) + ".sceneobject.getKey()"
elif NearOrFar == "Mid":
code = "target = SpawnMid0" + str(whichspawnpoint) + ".sceneobject.getKey()"
elif NearOrFar == "Far":
code = "target = SpawnFar0" + str(whichspawnpoint) + ".sceneobject.getKey()"
print "target code:", code
exec code
ShroomieMaster.sceneobject.physics.warpObj(target)
code = "respTrick0" + str(whichbehavior) + ".run(self.key)"
#~ print "code = ", code
exec code
CurrentTime = PtGetDniTime()
ageSDL["ShroomieTimeLastSeen"] = (CurrentTime,)
ShroomieTotalTimesSeen = ageSDL["ShroomieTotalTimesSeen"][0]
ShroomieTotalTimesSeen = ShroomieTotalTimesSeen + 1
ageSDL["ShroomieTotalTimesSeen"] = (ShroomieTotalTimesSeen,)
print "tldnShroomieBrain: Shroomie has been seen", ShroomieTotalTimesSeen,"times."
开发者ID:Aurebesh,项目名称:moul-scripts,代码行数:58,代码来源:tldnShroomieBrain.py
示例6: request_notice
def request_notice(self):
#probability factor
p = whrandom.randint(0, 100)
if p <= self.probibility:
#pick a random notice
r = whrandom.randint(0, self.num_notices-1)
return self.notice_names[r]
else:
return None
开发者ID:aevernon,项目名称:triggerman,代码行数:9,代码来源:newsroom.py
示例7: __init__
def __init__(self, one, two=None, retention=None):
self.dir = whrandom.randint(0,1)
self.dir = 1
if two==None:
match = self.entry_re.match(one)
retention = match.group('_3')
if retention == None: retention = whrandom.randint(0,(SIZE/2)-1)
else: retention = string.atoi(retention)
self.ret, self.one, self.two = retention, match.group('_1'), match.group('_2')
else:
self.ret, self.one, self.two = string.atoi(retention), one, two
开发者ID:lypanov,项目名称:wordcram,代码行数:11,代码来源:trainer.py
示例8: getSalt
def getSalt():
salt = ""
for j in range(2):
i = whrandom.randint(0,9)%3
if i == 0 :
i = (whrandom.randint(0,9)%11)
elif i == 1:
i = (whrandom.randint(0,9)%25)
elif i == 2:
i = (whrandom.randint(0,9)%25)
salt = salt + str(i)
return (salt)
开发者ID:theand,项目名称:once_upon_a_time,代码行数:12,代码来源:password.py
示例9: send_notice
def send_notice(self):
i = whrandom.randint(0, len(self.np)-1)
r = whrandom.randint(0, (self.np[i].num_notices)-1)
name_str = self.np[i].notice_names[r]
#msg_str = ''
snd_time = `time.time()`
msg_str = "('"+snd_time+"')"
bounded_name_str = "{"+name_str+"}"
print "DISPATCHER: send notice "+bounded_name_str+msg_str
notice_string = "send notice "+bounded_name_str+msg_str
tl(notice_string)
self.file_ptr.write('"'+name_str+'", '+snd_time+'\n')
开发者ID:aevernon,项目名称:triggerman,代码行数:14,代码来源:newsroom.py
示例10: shuffle
def shuffle(theList):
if type(theList) == type([]):
n = len(theList)
nmo = n - 1
numIter = int(n * math.log(n))
for x in range(numIter):
idx1 = whrandom.randint(0, nmo)
idx2 = whrandom.randint(0, nmo)
while idx1 == idx2:
idx1 = whrandom.randint(0, nmo)
idx2 = whrandom.randint(0, nmo)
theList[idx1], theList[idx2] = theList[idx2], theList[idx1]
开发者ID:Aurebesh,项目名称:moul-scripts,代码行数:15,代码来源:xRandom.py
示例11: cherrypick_best_from_list
def cherrypick_best_from_list(lst, num):
"""
Returns a list of length min(len(lst), num) items that have been
picked randomly from the list with an exponential distribution,
preferring to pick ones from the head of the list over the tail.
SIDE EFFECT: Removes picked items from lst.
"""
assert num >= 0
cherry_list = []
while lst and len(cherry_list) < num:
idx = whrandom.randint(0, whrandom.randint(0, len(lst)-1))
cherry_list.append(lst[idx])
del lst[idx]
return cherry_list
开发者ID:zooko,项目名称:egtp,代码行数:15,代码来源:mojoutil.py
示例12: choose
def choose(prev2, prev1):
count = 0
m = model[prev2][prev1]
total = reduce(lambda a, b: a+b, m)
n = whrandom.randint(1, m[26])
for i in range(27):
if m[i] >= n: return i
开发者ID:seanlynch,项目名称:homepage,代码行数:7,代码来源:namegen.py
示例13: choose
def choose(self):
"""Pick a random symbol from the list of symbols with the correct probability."""
total = 0
n = whrandom.randint(1, self.count)
for symbol, freq in self.freqs.items():
total = total + freq
if n <= total: return symbol
开发者ID:seanlynch,项目名称:pythonverse,代码行数:7,代码来源:microhal.py
示例14: Final
def Final(self):
"Calculate MD5 check sums, and pack it ready for sending."
import struct
from whrandom import randint
self.packlen=self.headlen + self.attrlen
self.code=1
self.id=randint(0,255)
# Do attributes
fmt="BBH16s%ds" % self.attrlen
if self.debug>0:
print "Constructing Packet"
args=[]
args.append(fmt)
args.append(int(self.code))
args.append(int(self.id))
args.append(int(self.packlen))
args.append(self.vector)
args.append(self.attributes)
self.packet=apply(struct.pack, tuple(args))
self.calledfinal=1
开发者ID:hazraa,项目名称:samples,代码行数:26,代码来源:radius.py
示例15: createToonDodgeMultitrack
def createToonDodgeMultitrack(tDodge, toon, leftToons, rightToons):
toonTracks = []
if len(leftToons) > len(rightToons):
PoLR = rightToons
PoMR = leftToons
else:
PoLR = leftToons
PoMR = rightToons
upper = 1 + 4 * abs(len(leftToons) - len(rightToons))
if whrandom.randint(0, upper) > 0:
toonDodgeList = PoLR
else:
toonDodgeList = PoMR
if toonDodgeList is leftToons:
sidestepAnim = 'sidestep-left'
for t in toonDodgeList:
toonTracks.append(Track([
(tDodge, ActorInterval(t, sidestepAnim)),
FunctionInterval(t.loop, extraArgs = [
'neutral'])]))
else:
sidestepAnim = 'sidestep-right'
toonTracks.append(Track([
(tDodge, ActorInterval(toon, sidestepAnim)),
FunctionInterval(toon.loop, extraArgs = [
'neutral'])]))
toonTracks.append(Track([
(tDodge, FunctionInterval(indicateMissed, extraArgs = [
toon]))]))
return MultiTrack(toonTracks)
开发者ID:Toonerz,项目名称:Toontown-2003,代码行数:31,代码来源:MovieUtil.py
示例16: __init__
def __init__(self,nick,passwd):
self._nick = nick
self._passwd = passwd
self._agent = "PY-TOC"
self._info = "I'm running the Python TOC Module by James Turner <[email protected]>"
self._seq = whrandom.randint(0,65535)
self.build_funcs()
开发者ID:pruan,项目名称:TestDepot,代码行数:7,代码来源:toc.py
示例17: randint
def randint(self, start, stop):
newInt = whrandom.randint(start, stop)
if type(_lastvalue) != type(None) and newInt == self._lastvalue:
if self._series_length >= self._MAX_SERIES:
while newInt == _lastvalue:
newInt = whrandom.randint(start, stop)
self._lastvalue = newInt
self._series_length = 1
else:
self._series_length = self._series_length + 1
else:
self._lastvalue = newInt
self._series_length = 1
return _lastvalue
开发者ID:Aurebesh,项目名称:moul-scripts,代码行数:16,代码来源:xRandom.py
示例18: __init__
def __init__(self, items, randomize=0):
"""
items is a list or tuple of items to "cycle through".
randomize, if false, means that as the cycler iterates
over objects, it starts at the beginning of items,
walks through the sequence in order, and returns to the start of
sequence after it has reached the last item.
If randomize is true, the cycler picks a random item in
the sequence as the "start item". Each iteration then jumps to
another, randomly chosen item in the sequence that is not
the same item as before. Thus, no item will be used twice in
a row.
"""
if type(items) not in (TupleType, ListType):
raise TypeError, "items %s must be a list or tuple" % repr(items)
if not items:
raise ValueError, "items %s must not be empty" % repr(items)
if len(items) < 2:
raise ValueError, "items %s must have more than one item" % repr(items)
self.items = items
self.randlen = len(items) - 1
self.randomize = randomize
if randomize:
self.pointer = randint(0, self.randlen)
else:
self.pointer = 0
开发者ID:BackupTheBerlios,项目名称:skunkweb-svn,代码行数:26,代码来源:Cycler.py
示例19: __init__
def __init__(self, file, rootdir, relthis):
root, ext = os.path.splitext(file)
html = root + '.html'
p = self.__parser = HTParser(file, self.AUTHOR)
f = self.__linkfixer = LinkFixer(html, rootdir, relthis)
self.__body = None
self.__cont = None
# calculate the sidebar links, adding a few of our own
self.__d = {'rootdir': rootdir}
p.process_sidebar()
p.sidebar.append(BLANKCELL)
# it is important not to have newlines between the img tag and the end
# end center tags, otherwise layout gets messed up
p.sidebar.append(('%(rootdir)s', '''
<center>
<img alt="" border=0
src="%(rootdir)s/pics/PythonPoweredSmall.gif"></center>
''' % self.__d))
self.__linkfixer.massage(p.sidebar, self.__d)
Sidebar.__init__(self, p.sidebar)
#
# fix up our site links, no relthis because the site links are
# relative to the root of our web pages
#
sitelink_fixer = LinkFixer(f.myurl(), rootdir)
sitelink_fixer.massage(sitelinks, self.__d, aboves=1)
Banner.__init__(self, sitelinks)
# calculate the random corner
# XXX Should really do a list of the pics directory...
NBANNERS = 64
i = whrandom.randint(0, NBANNERS-1)
s = "PyBanner%03d.gif" % i
self.__d['banner'] = s
self.__whichbanner = i
开发者ID:janbrohl,项目名称:PyXML,代码行数:34,代码来源:PDOGenerator.py
示例20: dummy
def dummy(n, results, lock):
print n, "running"
time.sleep(randint(1, 5))
lock.acquire()
results.append(n)
lock.release()
print n, "finished"
开发者ID:OS2World,项目名称:DEV-PYTHON-UTIL-ScientificPython,代码行数:7,代码来源:TaskManager.py
注:本文中的whrandom.randint函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论