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