• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python random.jumpahead函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中random.jumpahead函数的典型用法代码示例。如果您正苦于以下问题:Python jumpahead函数的具体用法?Python jumpahead怎么用?Python jumpahead使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了jumpahead函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: getSpawnsInRegion

    def getSpawnsInRegion(self, rx, rz):
        # Generate each spawn point and store in regionspawns, otherwise we just get the cached spawnpoints.
        if not (rx, rz) in self.worldspawns:
            # Seed the random number gen with all 64 bits of region coordinate data by using both seed and jumpahead
            random.seed( self.seed ^ ((rx & 0xFFFF0000) | (rz & 0x0000FFFF)) )
            random.jumpahead( ((rx & 0xFFFF0000) | (rz & 0x0000FFFF)) ) 
            # First number should be number of points in region
            numspawns = self.density
            rangetop = self.rangetop
            rangebottom = self.rangebottom

            self.worldspawns[ (rx,rz) ] = {}
            currentregion = self.worldspawns[ (rx,rz) ]
            for ix in xrange(numspawns):
                blockx = random.randint( 0, CHUNK_WIDTH_IN_BLOCKS * REGION_WIDTH_IN_CHUNKS - 1 ) + rx * CHUNK_WIDTH_IN_BLOCKS * REGION_WIDTH_IN_CHUNKS
                blockz = random.randint( 0, CHUNK_WIDTH_IN_BLOCKS * REGION_WIDTH_IN_CHUNKS - 1 ) + rz * CHUNK_WIDTH_IN_BLOCKS * REGION_WIDTH_IN_CHUNKS
                blocky = random.randint( max(0, rangebottom), min(CHUNK_HEIGHT_IN_BLOCKS - 1, rangetop) ) 
                currchunkx = blockx / CHUNK_WIDTH_IN_BLOCKS
                currchunkz = blockz / CHUNK_WIDTH_IN_BLOCKS
                # We store the points for each chunk indexed by chunk
                if not (currchunkx, currchunkz) in currentregion:
                    currentregion[ (currchunkx, currchunkz) ] = []
                # We make a landmark for each point
                lmtypeix = random.randint(0, len(self.landmarklist) - 1)
                lmtype = self.landmarklist[lmtypeix] 
                #lm = lmtype(self.seed, self.terrainlayer, blockx, blockz, blocky)
                lm = copy.copy(lmtype)
                lm.setPos(blockx, blockz, blocky)
                # Lastly we append the landmark to the chunk
                currentregion[ (currchunkx, currchunkz) ].append( lm )
        return self.worldspawns[ (rx,rz) ]
开发者ID:Chrisknyfe,项目名称:pymcworldgen,代码行数:31,代码来源:landmark.py


示例2: setUp

 def setUp(self): 
     random.jumpahead(int(time.time()))
     num = random.randint(1, 100000)
     self.input_table = self.input_table + "_" + str(num) 
     self.output_table = self.output_table + "_" + str(num)    
     #if (not os.getenv("HADOOP_CLASSPATH")):
     #    os.putenv("HADOOP_CLASSPATH", self.getjars(":"))
     dir = os.path.dirname(os.path.realpath(__file__))
     file = os.path.join( dir, 'splits' )  
     # code, out, err = cloudshell.run(self.username, self.password, 'table RowHashTestInput\n') 
     # if out.find('no such table') == -1:
     #    code, out, err = cloudshell.run(self.username, self.password, 'deletetable RowHashTestInput\n') 
     #    self.sleep(15)
     code, out, err = cloudshell.run(self.username, self.password, "createtable %s -sf %s\n" % (self.input_table, file))
     #code, out, err = cloudshell.run('table RowHashTest\n') 
     #if out.find('no such table') == -1:
     #    code, out, err = cloudshell.run('user root\nsecret\ndeletetable RowHashTest\n') 
     #    self.sleep(15)
     code, out, err = cloudshell.run(self.username, self.password, "createtable %s -sf %s\n" % (self.output_table, file))
     command = self.buildcommand('org.apache.accumulo.examples.simple.mapreduce.TeraSortIngest',
                                 self.numrows(),
                                 self.keysizemin(),
                                 self.keysizemax(),
                                 self.minvaluesize(),
                                 self.maxvaluesize(),
                                 self.input_table, 
                                 self.getInstance(),
                                 self.getZookeepers(),
                                 self.getUsername(),
                                 self.getPassword(),
                                 self.maxmaps)
     handle = runner.start(command, stdin=subprocess.PIPE)
     log.debug("Running: %r", command)
     out, err = handle.communicate("")  
     Benchmark.setUp(self)
开发者ID:Sciumo,项目名称:Accumulo,代码行数:35,代码来源:RowHashBenchmark.py


示例3: bootstrap

    def bootstrap(self, bootstrap_sample_size=1, seed=None):
        """
        Use bootstrapping to calculate the variance of the difference of two EFROC studies.

        :param bootstrap_sample_size: Number of times to resample. Defaults to 1.
        :param seed: Seed to initially pass to the random number generator. Defaults to None.

        :return: an ND Array of the bootstrapped differences.
        """
        difference_list = []
        gen = random.Random()
        gen.seed(seed)
        for count in xrange(bootstrap_sample_size):
            difference_list.append(self._resample_and_compare(gen))
            if seed is not None:
                random.jumpahead(seed)
        difference_array = np.array(difference_list)
        self.variance = np.var(difference_array)

        plt.figure()
        plt.hist(difference_array, np.ceil(np.sqrt(bootstrap_sample_size)), histtype='stepfilled')
        plt.title("Bootstrapped Estimation of $\delta A_{FE}$")
        plt.xlabel("$\delta A_{FE}$")
        plt.ylabel("Count")
        return difference_array
开发者ID:csteegz,项目名称:image-quality-roc,代码行数:25,代码来源:efroc.py


示例4: reduce_geoms

   def reduce_geoms(self,infile):
      if self.notrans == True:
         self.normalize()
      else:
         self.trans2intensity()
      self.finish_spectrum()
      toprint = "Original spectrum sigma: "+str(self.sigma)
      toprint += "\nPrinting original spectra:"
      self.writeoutall(infile,toprint)
      sys.stdout.flush()
      self.origintensity = self.intensity[:]
      self.exc_orig = self.exc
      self.trans_orig = self.trans
      self.nsample = self.subset

      jobs = []
      for i in range(self.ncores):
         pid = os.fork()
         if pid == 0:
            for j in range(self.jobs):
               self.pid = str(os.getpid())+"_"+str(j);
               random.seed()
               random.jumpahead(os.getpid())
               d = self.SA()
               toprint = str(self.pid)+":\tFinal D-min = "+str(d)
               toprint += "\n\tReduced spectrum sigma: "+str(self.sigma)
               toprint += "\n\tPrinting reduced spectra:"
               self.writeoutall(infile,toprint)
               self.writegeoms(infile)
               sys.stdout.flush()
            os._exit(0)
         jobs.append(pid)
      for job in jobs:
         os.waitpid(job,0)
开发者ID:PHOTOX,项目名称:photoxrepo,代码行数:34,代码来源:calc_spectrum.py


示例5: worker

def worker(lst):
    import random
    n, train_ds, test_ds, options, state =  lst
    random.setstate(state)
    random.jumpahead(n)
    preds, err = predict(train_ds, test_ds, options, True)
    return err
开发者ID:andreirusu,项目名称:mvpa-utils,代码行数:7,代码来源:PREDICT_NN.py


示例6: run

	def run(self):
		foo = time.time()
		random.jumpahead(self.N)
		time.sleep(random.random())
		
		for i in xrange(self.count):
			flag = Flag(0,i,0,foo)
			self.fc.enque(flag)
开发者ID:RootFu,项目名称:ctf-scorebot,代码行数:8,代码来源:TestFlagCollector.py


示例7: _make_salt

    def _make_salt(self, jump):
        salt_length = self._salt_length()
        seed = self._salt_seed()
        chars = string.ascii_uppercase + string.digits
        random.seed(seed)
        random.jumpahead(jump)

        return ''.join(random.choice(chars) for idx in range(salt_length))
开发者ID:chop-dbhi,项目名称:ehb-service,代码行数:8,代码来源:identities.py


示例8: __attack

	def __attack(self, game):
		if (game.frame > self.nextAttackFrame):
			## Spawn a new fruit at the monkey's location and let 'er fall!			
			guava = Guava(game, self.rect)
			game.sprites.append(guava)

			## Set the new time that the monkey should attack
			self.nextAttackFrame = game.frame + (1.0 / difficultyMul()) * random.randrange(15, 40)
			random.jumpahead(1)
开发者ID:rjzaar,项目名称:Speckpater,代码行数:9,代码来源:monkey.py


示例9: genWorkerID

def genWorkerID():
    global _randomized
    if not _randomized:
        random.jumpahead(os.getpid())
        _randomized = True
    return "worker-%02d-%02d-%02d" % (
        random.randint(0,99),
        random.randint(0,99),
        random.randint(0,99))
开发者ID:1stvamp,项目名称:apiary,代码行数:9,代码来源:hive.py


示例10: generateNextLine

    def generateNextLine( self ):
        random.jumpahead(random.randint(100,1000))
        
        line = []
        line.append( '|' )

        # This will be true for every row after the finish
        # line is generated.
        if self.rows > self.rowtarget:
            for i in range(0, 5):
                line.append(' ')
            line.append('|')
            return line

        # This will only be true when the target rows
        # have been hit
        if self.rows == self.rowtarget:
            for i in range(0, 5):
                line.append('=')
            line.append('|')
            return line

        # 1% chance to generate aroadblock
        if random.randint(0, 100) > 99:
            for i in range(0, 5):
                line.append( 'X' )
            line.append('|')
            # Needs at least one open space next to another one
            x = random.randint(0, 5)
            while self.state[2][x] != ' ':
                x = random.randint(0, 5)
            line[x] = ' '
            return line
        
        # Generate a normal line with 14% chance of an obstruction
        for i in range(0, 5):
            if random.randint(0, 100) > 86:
                type = random.randint(0, 5)
                if type == 0:
                    line.append( 'r' )
                elif type == 1:
                    line.append( 'c' )
                elif type == 2:
                    line.append( 'T' )
                elif type == 3:
                    line.append( 'P' )
                elif type == 4:
                    line.append( '~' )
                else:
                    line.append( 'Z' )
            else:
                line.append( ' ' )
            
        line.append( '|' )
        
        return line
开发者ID:0xBU,项目名称:ctfs,代码行数:56,代码来源:grandprix-inetd.py


示例11: do_test

def do_test(n, do_test_1=do_test_1):
    random.jumpahead(n*111222333444555666777L)
    N = 1
    TAIL = 'lo'
    objects = [None, -1, 0, 1, 123455+N, -99-N,
               'hel'+TAIL, [1,2], {(5,): do_test}, 5.43+0.01*N, xrange(5)]
    do_test_1(objects)
    for o in objects[4:]:
        #print '%5d  -> %r' % (sys.getrefcount(o), o)
        assert sys.getrefcount(o) == 4
开发者ID:Galland,项目名称:nodebox-opengl,代码行数:10,代码来源:test_compactobject.py


示例12: calcpi

def calcpi(n):

        random.seed(1)
        #n=decimal.Decimal(n)
        j=0
        random.jumpahead(n)
        for i in range(n):
                x,y=random.uniform(0,1),random.random()
                if x*x+y*y<=1.0: j+=1
        return n,4.0*float(j)/float(n)
开发者ID:mikitotanaka,项目名称:statistics16,代码行数:10,代码来源:day6_MCpi.py


示例13: randomizeFoodPos

 def randomizeFoodPos(self):
     e = 0
     while True:
         newFoodX = random.randint(1, self.blocks - 2)
         random.jumpahead(random.randint(1, self.blocks - 2))
         newFoodY = random.randint(1, self.blocks - 2)
         e += 1
         print("Randomizing " + str(e))
         if self.checkCollision(newFoodX, newFoodY) == 0 or e > 500:
             break
     self.food.setPos(newFoodX, newFoodY)
开发者ID:ClosedSauce,项目名称:Game1,代码行数:11,代码来源:gamestate.py


示例14: setUp

 def setUp(self): 
     random.jumpahead(int(time.time()))
     num = random.randint(1, 100000)   
     #self.tablename = self.tablename + "-" + str(num)  
     # Find which hadoop version
     # code, out, err = cloudshell.run(self.username, self.password, 'table %s\n' % self.tablename)
     #if out.find('no such table') == -1:
     #    log.debug('Deleting table %s' % self.tablename)
     #    code, out, err = cloudshell.run(self.username, self.password, 'deletetable %s\n' % self.tablename)
     #    self.sleep(10)
     Benchmark.setUp(self)
开发者ID:Sciumo,项目名称:Accumulo,代码行数:11,代码来源:TeraSortBenchmark.py


示例15: __init__

 def __init__(self, name):
     self.name = name
     self.instance = Client.instance
     Client.instance += 1
     self.sock = socket.socket()
     self.rx_msg_q = Queue.Queue()
     self.receive_thread = Thread( target=self.receive_loop )
     self.receive_thread.daemon = True
     self.action_thread = Thread( target=self.action_loop )
     self.action_thread.daemon = True
     self.print_msgs = True
     self.complete = False
     random.jumpahead( self.instance+5000 )
开发者ID:mildmongrel,项目名称:thicket,代码行数:13,代码来源:client.py


示例16: setUp

 def setUp(self): 
     random.jumpahead(int(time.time()))
     num = random.randint(1, 100000)
     self.tablename = self.tablename + "_" + str(num)     
     # Need to generate a splits file for each speed
     #code, out, err = cloudshell.run(self.username, self.password, 'table %s\n' % self.tablename)
     #if out.find('no such table') == -1:
     #    log.debug('Deleting table %s' % self.tablename)
     #    code, out, err = cloudshell.run('user %s\n%s\ndeletetable %s\n' % (self.user, 
     #                                                                          self.password, 
     #                                                                          self.tablename))
     #    self.sleep(5)
     Benchmark.setUp(self)
开发者ID:Sciumo,项目名称:Accumulo,代码行数:13,代码来源:TableSplitsBenchmark.py


示例17: __init__

	def __init__(self, g, pos):
		def hit_handler(g, s, a):
			pass

		Sprite.__init__(self, g.images['monkey_0_1'], pos)
		self.groups = g.string2groups('enemy')
		self.agroups = g.string2groups('player')
		self.anim_frame = random.randrange(1, 5)
		self.hit = hit_handler

		## How often the monkey should attack. Higher numbers = more infrequent
		self.nextAttackFrame = random.randrange(0, 10)
		random.jumpahead(1)
开发者ID:rjzaar,项目名称:Speckpater,代码行数:13,代码来源:monkey.py


示例18: process_in_fork

def process_in_fork(function, display, processes, timeout):
    """make rules, in background processes"""
    children = []
    for i in range(processes):
        print "handling child %s" %i
        child = fork_safely()
        #without this jump all the processes will give the same answer
        random.jumpahead(11)
        if not child:
            #in child
            try:
                print "in child %s, to run %s" % (i, function)
                #os._exit(0)
                function()
                print "in child %s, after %s" % (i, function)
            except:
                print "in child %s, with exception" % (i)
                #exception will kill X window (and thus main process),
                #so catch everything
                traceback.print_exc()
                sys.stderr.flush()
            print "in child %s, wleaving" % (i,)
            os._exit(0)
        children.append(child)

    # now, twiddle thumbs
    timeout += time.time()
    results = []
    while children and time.time() < timeout:
        if display is not None:
            display()
        pid, status = os.waitpid(-1, os.WNOHANG)
        if pid in children:
            children.remove(pid)
            print "got pid %s, status %s" % (pid, status)
            if not status:
                results.append(pid)
    #final chance -- no display/delay
    for i in range(len(children)):
        pid, status = os.waitpid(-1, os.WNOHANG)
        children.remove(pid)
        print "got (late) pid %s, status %s" % (pid, status)
        if not status:
            results.append(pid)


    if children:
        print "getting violent with children %s" % children
        for pid in children: #kill slowcoaches, if any
            os.kill(pid, 9)
    return results
开发者ID:douglasbagnall,项目名称:tetuhi,代码行数:51,代码来源:utils.py


示例19: test_jumpahead

def test_jumpahead():
    """jumpahead will change the pseudo-number generator's internal state
    """
    random.seed()
    state1 = random.getstate()
    random.jumpahead(20)
    state2 = random.getstate()
    rep = 0
    for ind in range(len(state1)):
        elem1 = state1[ind]
        elem2 = state2[ind]
        if (elem1 == elem2): rep += 1
    if (rep > len(state1) / 2):
        raise "state1 and state2 can't be the same"
开发者ID:HarryR,项目名称:tinypy-panda,代码行数:14,代码来源:tests.py


示例20: my_reduce

 def my_reduce(self, key, values):
     random.jumpahead(key[1])
     best = None
     for value in values:
         wyn = wynik_zachlanny(value)
         if best == None:
             best = value
             bestval = sum([x[-1] for x in wyn])
         else:
             actval = sum([x[-1] for x in wyn])
             if actval < bestval:
                 bestval = actval
                 best = value
     yield key[0], best
开发者ID:sebastianjaszczur,项目名称:MRwiki,代码行数:14,代码来源:s12b-genetic.py



注:本文中的random.jumpahead函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python random.lognormvariate函数代码示例发布时间:2022-05-26
下一篇:
Python random.getstate函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap