def OnFirstUpdate(self): self.AlreadyPlayed = 0 self.IsTalking = 0 self.IsIgnoring = 0 self.DoingBehavior = 0 self.NearZandi = 0 self.PlayWelcome2 = 0 self.LastSpeech = -1 self.PlayOnFinish = 0 whrandom.seed() vault = ptVault() #~ entry = vault.findChronicleEntry("JourneyClothProgress") #~ if type(entry) != type(None): #~ FoundJCs = entry.chronicleGetValue() #~ if "Z" in FoundJCs: #~ PtPageOutNode("clftZandiVis") #~ print "Zandi seems to have stepped away from the Airstream. Hmmm..." entry = vault.findChronicleEntry("YeeshaVisionViewed") if type(entry) == type(None): vault.addChronicleEntry("YeeshaVisionViewed", 0, "0") PtAtTimeCallback(self.key, PageTurnInterval, TimerID.TurnPage)
def main(): """Main program when invoked as a script. One argument: tabulate a single row. Two arguments: tabulate a range (inclusive). Extra arguments are used to seed the random generator. """ import string # default range (inclusive) k1 = 15 k2 = 19 if sys.argv[1:]: # one argument: single point k1 = k2 = string.atoi(sys.argv[1]) if sys.argv[2:]: # two arguments: specify range k2 = string.atoi(sys.argv[2]) if sys.argv[3:]: # derive random seed from remaining arguments x, y, z = 0, 0, 0 for a in sys.argv[3:]: h = hash(a) h, d = divmod(h, 256) h = h & 0xffffff x = (x^h^d) & 255 h = h>>8 y = (y^h^d) & 255 h = h>>8 z = (z^h^d) & 255 whrandom.seed(x, y, z) r = range(k1, k2+1) # include the end point tabulate(r)
def main(): """Main program when invoked as a script. One argument: tabulate a single row. Two arguments: tabulate a range (inclusive). Extra arguments are used to seed the random generator. """ import string # default range (inclusive) k1 = 15 k2 = 19 if sys.argv[1:]: # one argument: single point k1 = k2 = string.atoi(sys.argv[1]) if sys.argv[2:]: # two arguments: specify range k2 = string.atoi(sys.argv[2]) if sys.argv[3:]: # derive random seed from remaining arguments x, y, z = 0, 0, 0 for a in sys.argv[3:]: h = hash(a) h, d = divmod(h, 256) h = h & 0xffffff x = (x ^ h ^ d) & 255 h = h >> 8 y = (y ^ h ^ d) & 255 h = h >> 8 z = (z ^ h ^ d) & 255 whrandom.seed(x, y, z) r = range(k1, k2 + 1) # include the end point tabulate(r)
def seed(a=None): """Seed the default generator from any hashable value. None or no argument seeds from current time. """ x, y, z = makeseed(a) whrandom.seed(x, y, z)
def OnFirstUpdate(self): global PlayFull global AgeStartedIn AgeStartedIn = PtGetAgeName() PtUnloadDialog("YeeshaPageGUI") whrandom.seed() self.CloseImager(1)
def OnServerInitComplete(self): xRandom.seed((PtGetDniTime() % 256)) whrandom.seed() PtClearTimerCallbacks(self.key) respBaseStop.run(self.key, fastforward=1) respPeakStop.run(self.key, fastforward=1) self.NextQuakeDelay() ageSDL = PtGetAgeSDL() ageSDL.sendToClients(sdlCanQuake.value) ageSDL.setFlags(sdlCanQuake.value, 1, 1) ageSDL.setNotify(self.key, sdlCanQuake.value, 0.0)
def main(options, arguments): global configuration try: myconfiguration = load_system(options, arguments) except KeyboardInterrupt: raise SystemExit # Set seed for random-number functions whrandom.seed(int(time.time()) % 256, os.getpid() % 256, 23) global grafittishuffle grafittishuffle = shuffle(len(grafitti)) print lang["WELCOME"] % cml.version myconfiguration.errout = sys.stdout advent_menu(configfile, banner).cmdloop()
def set_seed(seed_val): "seed the random number generator and print out that seed" # If no seed value or a value of 0 was specified at the # command line, get a new random value if seed_val == 0: seed_val = randint(0, 255) # Output the seed value str = "Seed value = "+`seed_val` print str echo (str) # Seed the random number generator with this value whrandom.seed(seed_val)
def validate_wichmannhill(): """ The WichmannHill validation checks that the same results are produced for the crng implementation (in C) as the whrandom implementation (in Python) as delivered in the standard Python library. The test checks the first 1000 numbers from the same seeds. """ import whrandom whrandom.seed(1, 2, 3) w = crng.WichmannHill(1, 2, 3) for i in range(1, 1001): x = "%10.8f" % whrandom.random() y = "%10.8f" % w.next() if x != y: raise crngError, "WichmannHill value (iteration %i) is %s, should be %s" % ( i, y, x)
def _help_test_skim(FUNC, SETSIZE, MAXVAL, NUMWANTED): whrandom.seed(0,0,0) d = {} for i in range(SETSIZE): d[i] = whrandom.randint(0, MAXVAL) db = {} db.update(d) FUNC(d, NUMWANTED) l = d.items() l.sort(lambda a, b: cmp(b[1], a[1])) l2 = db.items() l2.sort(lambda a, b: cmp(b[1], a[1])) l2 = l2[:NUMWANTED] for i in range(NUMWANTED): assert l[i][1] == l2[i][1], "i: %s, l: %s, l2: %s" % (`i`, `l`, `l2`)
def main(argc, argv): import sendmail progname = argv[0] alist, args = getopt.getopt(argv[1:], "", ["help", "num=", "fork=", ]) num = 1 fork = 0 random_from = 1 if len (args) < 1: usage (progname) return for (field, val) in alist: if field == "--help": usage(progname) return if field == "--num": num = int (val) if field == "--fork": fork = int (val) mailto = args[0] if len (args) > 1: email = args[1] random_from = 0 if len (args) > 2: author = args[2] print "Creating %d processes" % fork while (fork): pid = os.fork() if pid == 0: # In child whrandom.seed (int(time.time()) % 256, fork % 256, os.getpid() % 256) fork = 0 print "Created Child Process" else: # In parent fork = fork - 1 for x in range (num): now = time.time() def date_header (time_t): sec_offset = 0 tup = time.gmtime(time_t + sec_offset) datestr = time.strftime("%a, %d %b %Y %H:%M:%S", tup) if sec_offset <= 0: sign = '-' else: sign = '+' return "%s %s%02d00" % (datestr, sign, abs(sec_offset / 3600)) date = date_header(now) rseed = int(now * 1000 % 10000000) cmd = "/usr/local/bin/dada -w 68 -r %d %s" % (rseed, args[1]) print cmd msg = os.popen(cmd, "r").read() lines = string.split(msg, '\n') email = lines[0] lines[0] = "Date: %s" % date msg = string.join(lines, '\n') print "Message sent to %s from %s\n" % ( mailto, email) sendmail.sendmail(email, [mailto], msg)
i = 0 nums = [] for l in f.readlines(): w = l.split() if len(w) < 8: continue for n in w[2:]: nums.append(int(n)) i += 1 if i>=2: break return nums if __name__=="__main__": whrandom.seed() getRatioSum() myNum = myNum + add_real_lottonum('lotto.data') print myNum all = [] for i in range(10): print "----", i, "----" list = selNfromList(myNum, 6) print "Magic Num:", list res = getLotto( list ) print "Lotto Num:", res res.sort() #print "Lotto Num:", res all.append(res)
def OnFirstUpdate(self): whrandom.seed()
"""Sort performance test.
def OnServerInitComplete(self): whrandom.seed()
def seed(var=0): if type(var) == type(1): whrandom.seed(var) else: whrandom.seed()
def getargs(): global size, sparseness, symmetric, tridiagonal, suffix try: options, args = getopt.getopt(sys.argv[1:], 'n:s:STr:F:h') except getopt.error, message: sys.stderr.write(message + '\n') print __doc__ sys.exit(1) for opt in options: if opt[0] == '-n': size = string.atoi(opt[1]) elif opt[0] == '-s': sparseness = string.atof(opt[1]) elif opt[0] == '-r': seed = string.atoi(opt[1]) whrandom.seed(seed, 0, 1) elif opt[0] == '-S': symmetric = 1 elif opt[0] == '-T': tridiagonal = 1 elif opt[0] == '-F': suffix = "." + opt[1] elif opt[0] == '-h': print __doc__ sys.exit(0) def make_mtx(): mat = SparseLinkMat(size, size) if tridiagonal: for i in range(size):
def dataSend(f, data): if data[-1] != '\n': data = data + '\n' numLines = string.count(data, '\n') f.write('%d\n' % numLines) f.write(data) f.flush() def dataRecv(f): line = f.readline() if not line: return None numLines = string.atoi(line) data = [] for i in range(numLines): data.append(f.readline()) return string.join(data, '') def smimeSend(f, smime): return dataSend(f, smime) def smimeRecv(f): return dataRecv(f) whrandom.seed(int(time.time()) % 256, os.getpid() % 256, os.getppid() % 256)
##print "Insertion time: " + `time() - start` + " seconds." ## ##print "Dropping all triggersets" ##start = time() ##tl("drop all triggersets") ##print "Drop time: " + `time() - start` + " seconds." ## ##print "Inserting " + `TRIGGERS` + " triggers in database again" ##start = time() ##tl("source '" + filename + "'") ##print "Insertion time: " + `time() - start` + " seconds." DROPS = 1000 print "Dropping " + `DROPS` + " random triggers in database..." whrandom.seed(0,0,0) # x = y = z ==> use current time as seed # We'll keep track of the triggers we drop in used_indices, and the time # in times used_indices = [] times = [] for i in range(0, DROPS) : iTrig = int(math.floor(whrandom.random() * TRIGGERS)) while (used_indices.count(iTrig) > 0) : iTrig = int(math.floor(whrandom.random() * TRIGGERS)) used_indices.append(iTrig) if i % 50 == 0 : print "Done with " + `i` + " drops." start = time()
def OnServerInitComplete(self): global AllItems return ageSDL = PtGetAgeSDL() # pick items to display whrandom.seed() ItemsToPick = whrandom.randint(kMinNumItems, kMaxNumItems) AlreadyPicked = [ ] while len(AlreadyPicked) < ItemsToPick: randitem = whrandom.choice(AllItems) if randitem not in AlreadyPicked: AlreadyPicked.append (randitem) for item in AlreadyPicked: if (item == "grsnPrisonBones01vis"): ageSDL["grsnPrisonBones01vis"]=(1,) if (item == "grsnPrisonBones02vis"): ageSDL["grsnPrisonBones02vis"]=(1,) if (item == "grsnPrisonBowls01vis"): ageSDL["grsnPrisonBowls01vis"]=(1,) if (item == "grsnPrisonBowls02vis"): ageSDL["grsnPrisonBowls02vis"]=(1,) if (item == "grsnPrisonBowls03vis"): ageSDL["grsnPrisonBowls03vis"]=(1,) if (item == "grsnPrisonBowls04vis"): ageSDL["grsnPrisonBowls04vis"]=(1,) if (item == "grsnPrisonBowls05vis"): ageSDL["grsnPrisonBowls05vis"]=(1,) if (item == "grsnPrisonChains01vis"): ageSDL["grsnPrisonChains01vis"]=(1,) if (item == "grsnPrisonChains02vis"): ageSDL["grsnPrisonChains02vis"]=(1,) if (item == "grsnPrisonDirt01vis"): ageSDL["grsnPrisonDirt01vis"]=(1,) if (item == "grsnPrisonDirt02vis"): ageSDL["grsnPrisonDirt02vis"]=(1,) if (item == "grsnPrisonMattress01vis"): ageSDL["grsnPrisonMattress01vis"]=(1,) if (item == "grsnPrisonMattress02vis"): ageSDL["grsnPrisonMattress02vis"]=(1,) if (item == "grsnPrisonWindow01vis"): ageSDL["grsnPrisonWindow01vis"]=(1,) if (item == "grsnPrisonWindow02vis"): ageSDL["grsnPrisonWindow02vis"]=(1,) self.IManageYeeshaPage()
def OnFirstUpdate(self): xRandom.seed((PtGetDniTime() % 256)) whrandom.seed() PtClearTimerCallbacks(self.key) self.NextQuakeDelay()
line = f.readline() if not line: return None return string.atoi(line) def dataSend(f, data): if data[-1] != '\n': data = data + '\n' numLines = string.count(data, '\n') f.write('%d\n' % numLines) f.write(data) f.flush() def dataRecv(f): line = f.readline() if not line: return None numLines = string.atoi(line) data = [] for i in range(numLines): data.append(f.readline()) return string.join(data, '') def smimeSend(f, smime): return dataSend(f, smime) def smimeRecv(f): return dataRecv(f) whrandom.seed(int(time.time()) % 256, os.getpid() % 256, os.getppid() % 256)
# Module 'rand'
def srand(seed): whrandom.seed(seed % 256, seed / 256 % 256, seed / 65536 % 256)
def seed(var = 0): if type(var) == type(1): whrandom.seed(var) else: whrandom.seed()
def seed(self, var=0): whrandom.seed(var)
def srand(seed): whrandom.seed(seed%256, seed/256%256, seed/65536%256)
cd lib/python python Products/ZCatalog/regressiontests/loadmail.py base ~/zope.mbox 1000 python Products/ZCatalog/regressiontests/loadmail.py index 100 python Products/ZCatalog/regressiontests/loadmail.py \ inc ~/python-dev.mbox 0 10 2 python Products/ZCatalog/regressiontests/loadmail.py edit 10 10 10 2 """ import mailbox, time, sys, os, string sys.path.insert(0, '.') import whrandom whrandom.seed(1,2,3) from string import strip, find, split, lower, atoi from urllib import quote def do(db, f, args, returnf=None): """Do something and measure it's impact""" t = c = size = mem = r = None try: size=db.getSize() mem=VmSize() t=time.time() c=time.clock() r=apply(f, args) t=time.time() - t c=time.clock() - c
res.nglFrame = False # or advance the frame res.mpProjection = "LambertConformal" plot = Ngl.map(wks,res) # create the map plot # # Polygon resources. # res_poly = Ngl.Resources() res_poly.gsEdgesOn = True # draw border around polygons. res_poly.gsEdgeColor = "black" # # Prepare to draw the polygons. # whrandom.seed(1,2,3) # set a seed for the random number generator # # Get the polygon data and fill polygons with random colors in # the range of our color table (2-31). # for st in xrange(npoly): for cd in xrange(ncds[st]): rand_num = int(29.*whrandom.random()+2.) if (st == 42 and cd == 0): # save value va1_rn = rand_num # VA clim div 1 if (st == 42 and cd == 6): # use value for res_poly.gsFillColor = va1_rn # VA clim div 1 else: res_poly.gsFillColor = rand_num varstr = statenames[st]+"_CD" + str(cd+1)
print " PYPVM is not correctly installed.\n\ Please refer to the README and INSTALL files for a solution." sys.exit(0) from Serialize import * from StringUtil import * import os import time import code import re import whrandom from string import * SVMs = {} whrandom.seed() def random_comp(a, b): return whrandom.randint(-1, 1) def long_first_comp(a, b): if len(a) > len(b): return -1 elif len(a) < len(b): return 1 else: return cmp(a, b)
def __init__(self, parent, nparticles=4, update=1, nsteps=10, particle_frame=0, seed1=1, seed2=2, seed3=3, w=400, h=400): whrandom.seed(seed1, seed2, seed3) # fix the seed print 'first random number=', whrandom.random() self.master = parent frame = Frame(parent, borderwidth=2) frame.pack() self.frame_width = w self.frame_height = h print 'w=', self.frame_width, 'h=', self.frame_height self.canvas = c = Canvas(frame, width=self.frame_width, height=self.frame_height, background='black') c.pack() self.nparticles = nparticles self.update = update # continuous movement or not self.nsteps = nsteps scratch = Numeric.zeros(w * h, Numeric.Int) self.occupied = Numeric.reshape(scratch, (w, h)) self.finished = 0 self.master.bind('q', self.quit) self.particle_color = 'blue' self.particle_frame = particle_frame self.freespace = 10 + 2 * (particle_frame - 1) # seed: self.seed = self.coor(self.frame_width / 2, self.frame_height / 2) p = self.createParticle(self.seed) self.occupied[p[1], p[2]] = 1 # mark occupied array # inner frame: self.ifxmin = self.ifxmax = p[1] self.ifymin = self.ifymax = p[2] self.changeBoundingBox(p[1], p[2]) xc1, yc1, xc2, yc2 = self.coor4(self.ifxmin, self.ifymin, self.ifxmax, self.ifymax) c.create_rectangle(xc1, yc1, xc2, yc2, tags='boundingbox', outline='green') self.particles = [] for p in range(self.nparticles): self.particles.append( self.createParticle(self.randomPointOnInnerFrame())) c0 = time.clock() color = 1 forward = 1 for self.step in range(self.nsteps): if self.finished: break if self.step % 50 == 0: color = color % 255 + 1 # 2,3,4,...,255 if forward: # blue to green: self.particle_color = '#%02x%02x%02x' % (0, color, 255) else: # reverse back to blue: self.particle_color = '#%02x%02x%02x' % (0, 256 - color, 255) if color == 255: forward = not forward for p in self.particles: self.move(p) # if continuous update, update for each particle move: #if self.update: self.master.update() # update here is more efficient: if self.update: self.master.update() if self.finished: break # finished! cpu = time.clock() - c0 print 'CPU-time of this simulation:', cpu, 'seconds' print 'dla.ps contains a PostScript plot of the DLA' # in the PostScript plot, the extent of the particles must # be non-zero, set them to 1 (in canvas coordinate measurement): items = self.canvas.find_all() print len(items), 'particles in this simulation' for item in items: # run through all items coor = self.canvas.coords(item) # grab particle coordinates coor[2] = coor[2] + 1 coor[3] = coor[3] + 1 self.canvas.coords(item, coor[0], coor[1], coor[2], coor[3]) try: self.canvas.delete('boundingbox') except: pass self.canvas.postscript(file='dla.ps')
def seed(self, var = 0): whrandom.seed(var)