当前位置: 首页>>代码示例>>Python>>正文


Python random.choice函数代码示例

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


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

示例1: neighbor_switch_jumps

def neighbor_switch_jumps(state):
    big_jumps = find_big_jumps(state)
    goodTrks = good_tracks(state)
    track1=random.choice(goodTrks)
    track2 = random.choice(goodTrks)


    num_of_jumps = len(big_jumps[track1])
    if num_of_jumps >= 1:
        which_jump = randint(0,num_of_jumps-1)
        time_jump1 = big_jumps[track1][0]
        temp = state[track1][time_jump1:lifetime]
        state[track1][time_jump1:lifetime] = state[track2][time_jump1:lifetime]
        state[track2][time_jump1:lifetime] = temp



    '''elif num_of_jumps>2:
        print('num of jumps' + str(num_of_jumps))
        print('list of big jumps' + str(big_jumps))
        which_jump = randint(0,num_of_jumps-2)
        print('which jump : ' + str(which_jump))
        time_jump1 = big_jumps[track1][which_jump]
        time_jump2= big_jumps[track1][which_jump+1]

        temp = state[track1][time_jump1:time_jump2]
        state[track1][time_jump1:time_jump2] = state[track2][time_jump1:time_jump2]
        state[track2][time_jump1:time_jump2] = temp
    '''

    return state
开发者ID:stellastyl,项目名称:trackingfoci,代码行数:31,代码来源:tracking_2.py

示例2: count_helper

 def count_helper(diamonds,clubs,hearts,spades):
    random.choice("diamonds","clubs","hearts","spades")
    if random.choice=="diamonds":
       return count_helper(diamonds+1,hand-1)
      elif random.choice=="clubs":
         return count_helper(clubs+1,hand-1)
      elif random.choice=="hearts"
         return count_helper(hearts+1,hand-1)
      else:
         return count_helper(spades+1,hand-1)
开发者ID:KWMalik,项目名称:organization,代码行数:10,代码来源:a6.py

示例3: gen_cc_external

def gen_cc_external(merchant,no_trans,count):
	for i in range(no_trans):
		acct=random.choice(python_account_ID.accountid)
		cc_list=python_CC.CC_Dict[acct]
		#7)Set customer credit limit - skew to clients with $1000-$25000 and 10% with $25K - $50K
		limit = max(max((randrange(1,101,1)-99),0)* randrange(25000,50000,1000),randrange(1000,25000,1000))
		#local Amt variable to calculate customer total usage
		usedAmt = 0
		maxDate= datetime(0001,01,01) 
		NoTrans = randrange(100,150,1)
		#loop to generate NoTrans transactions per customer, we can add logic for probabilities of # transactions if neccessary random number generator to avoid the constant value
		for j in range(NoTrans):
			dt = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
			#generate amount for current transaction with 50%-50% distribution on credits and debits
			tmpAmt = max((randrange(1,3,1)-1),0)* randrange(1,limit,100)*(-1)
			#if not credit then generate debit
			if tmpAmt == 0:
				tmpAmt = randrange(1,limit,100)
			#add current amount to client total account usage
			usedAmt = usedAmt + tmpAmt
			#pull value from dictionary for randomly selected merchant category 
			cat = ''
			tranType = ''
			row = [str(count)+'_'+dt] + [acct] + [gen_data.create_company_name()] 
			#set transaction type based on amount
			if tmpAmt < 0:
				tranType = random.choice(Transaction_Type_Credits)
				row.append('Non-BMO Acct')
				row.append('')
			else: 
				tranType = random.choice(Transaction_Type_Debits)
				cat = random.choice(merchant)
				row.append(cat)
				row.append(python_merchant_cat.All_Merchant_Cat[cat])
			#tranType random.choice(Transaction_Type)
			
			#date posted
			date1 = gen_data.create_date(past=True)
			if date1 > maxDate:
				maxDate = date1
			#date of transaction a day later
			date2 = date1-timedelta(days=1)
			row.extend([date1, date2, tranType,random.choice(Country_Red),limit,tmpAmt,usedAmt,cc_list[0],cc_list[1]])
			count = count + 1
			writer.writerow(row)
		#post generating all transactions, check account balance - if overpaid - refund $ and add a refun transaction 
		if usedAmt < limit * (-1):
			row = [str(count)+'_'+dt]+ [acct] + ['']+['']+['']
			date1temp=maxDate+timedelta(days=90)
			date2=date1temp-timedelta(days=1)
			row.extend([date1temp, date2, 'Refund','',limit,abs(limit-abs(usedAmt))*(-1),0,cc_list[0],cc_list[1]])
			count = count + 1
			usedAmt = 0
			maxDate= datetime(0001,01,01)
			writer.writerow(row)
开发者ID:JSuelfl,项目名称:Credit-Card-Model,代码行数:55,代码来源:Old_CC_TranGenerator.py

示例4: neighbor

def neighbor(state):
    # make random change in random number of spots
    # swap random range
    timepoint = randint(0, lifetime - 1)
    goodTrks = good_tracks(state)
    track1=random.choice(goodTrks)
    goodTrks.remove(track1)
    track2=random.choice(goodTrks)
    temp = state[track1][timepoint:lifetime]
    state[track1][timepoint:lifetime] = state[track2][timepoint:lifetime]
    state[track2][timepoint:lifetime] = temp

    return state
开发者ID:stellastyl,项目名称:trackingfoci,代码行数:13,代码来源:tracking_2.py

示例5: detTime

def detTime():
    #temporary solution
    global currentTime
    global itemn
    global items
    global itemw
    global iteme
    now=getTimeStamp()
    if(now-currentTime>interval):
	itemn=random.choice(item0)
	items=random.choice(item1)
	itemw=random.choice(item2)
	iteme=random.choice(item3)
	currentTime=now
开发者ID:indosandi,项目名称:DemStore,代码行数:14,代码来源:item.py

示例6: calc_sim_rec

def calc_sim_rec(dist_df,likes,dislikes,n=0,larger_is_closer=True):
	if likes == []:
		return random.choice(dist_df.index)
	else:
		#dists_df = dist_df[dist_df.index.isin(cluster_dict)]
		p = get_sims(list(likes),list(dislikes),dist_df,n,larger_is_closer)
		return p[0:n]
开发者ID:dgreenfi,项目名称:ImageRec,代码行数:7,代码来源:distance.py

示例7: __randomInvasionTick

    def __randomInvasionTick(self, task=None):
        """
        Each hour, have a tick to check if we want to start an invasion in
        the current district. This works by having a random invasion
        probability, and each tick it will generate a random float between
        0 and 1, and then if it's less than or equal to the probablity, it
        will spawn the invasion.

        An invasion will not be started if there is an invasion already
        on-going.
        """
        # Generate a new tick delay.
        task.delayTime = randint(1800, 5400)
        if self.getInvading():
            # We're already running an invasion. Don't start a new one.
            self.notify.debug('Invasion tested but already running invasion!')
            return task.again
        if random() <= self.randomInvasionProbability:
            # We want an invasion!
            self.notify.debug('Invasion probability hit! Starting invasion.')
            # We want to test if we get a mega invasion or a normal invasion.
            # Take the mega invasion probability and test it. If we get lucky
            # a second time, spawn a mega invasion, otherwise spawn a normal
            # invasion.
            if config.GetBool('want-mega-invasions', False) and random() <= self.randomInvasionProbability:
                # N.B.: randomInvasionProbability = mega invasion probability.
                suitName = self.megaInvasionCog
                numSuits = randint(2000, 15000)
                specialSuit = random.choice([0, 0, 0, 1, 2])
            else:
                suitName = choice(SuitDNA.suitHeadTypes)
                numSuits = randint(1500, 5000)
                specialSuit = False
            self.startInvasion(suitName, numSuits, specialSuit)
        return task.again
开发者ID:Toonerz,项目名称:Toontown-World-Online-Leaked-Source,代码行数:35,代码来源:SuitInvasionManagerAI.py

示例8: calc_sim

def calc_sim(dist_df,likes,dislikes,cluster_dict=None,cluster_no=None,n=0):
	if likes == []:
		return random.choice(cluster_dict[cluster_no])
	else:
		if cluster_dict != None and cluster_no != None:
			dists_df = dist_df[dist_df.index.isin(cluster_dict[cluster_no])]
		p = get_sims(list(likes),list(dislikes),dists_df,larger_is_closer=True)
		return p[n]
开发者ID:dgreenfi,项目名称:ImageRec,代码行数:8,代码来源:distance.py

示例9: neighbor_onespot

def neighbor_onespot(state):
    # make random change for one random spots
    timepoint = randint(0, lifetime - 2)
    goodTrks = good_tracks(state)
    track1=random.choice(goodTrks)
    goodTrks.remove(track1)
    track2=random.choice(goodTrks)
    temp = state[track1][timepoint]
    state[track1][timepoint] = state[track2][timepoint]
    state[track2][timepoint] = temp


    temp2 = state[track1][timepoint+1]
    state[track1][timepoint+1] = state[track2][timepoint+1]
    state[track2][timepoint+1] = temp2

    return state
开发者ID:stellastyl,项目名称:trackingfoci,代码行数:17,代码来源:tracking_2.py

示例10: place_random

 def place_random(self, entity):
     empty = []
     for x in range(0, self.width):
         for y in range(0, self.height):
             if self[x, y] is None:
                 empty.append((x, y))
     if len(empty) == 0:
         raise World.FullRoomException()
     self[random.choice(empty)] = entity
开发者ID:ryanhornik,项目名称:cursed,代码行数:9,代码来源:world.py

示例11: create_expression

def create_expression():
    """This function takes no arguments and returns an expression that
    generates a number between -1.0 and 1.0, given x and y coordinates."""
    expr1 = lambda x, y: (x + y)/2 * cos(y) * tan(5 ** 4) *cos(pi * sin(pi * cos))
    expr2 = lambda x, y: (x - y)/2 * random()
    expr3 = lambda x, y: x * y/4 * random()
    expr4 = lambda x, y: tan(6 * x) * cos(x)
    expr5 = lambda y, x: (sin(pi)) + tan(y**2)
    return random.choice([expr1, expr2, expr3, expr4, expr5])
开发者ID:msk007,项目名称:09--Modern-Art--Michael-Krawiec,代码行数:9,代码来源:random_art.py

示例12: alpha_num_password

def alpha_num_password(wordLen=8):
    import random

    for k in range(200):
        word = ''

        for i in range(wordLen):
            word += random.choice('1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstu')

    print word
开发者ID:wolfprogrammer,项目名称:password-generator,代码行数:10,代码来源:passgen.py

示例13: strong_password

def strong_password(wordLen=8):
    import random

    for k in range(200):
        word = ''

        for i in range(wordLen):
            word += random.choice('-+_()*&$#@!<>;?|{}"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstu')

    print word
开发者ID:wolfprogrammer,项目名称:password-generator,代码行数:10,代码来源:passgen.py

示例14: alpha_uppercase

def alpha_uppercase(wordLen=8):
    import random

    for k in range(200):
        word = ''

        for i in range(wordLen):
            word += random.choice('abcdefghijklmnopqrstuz')

    print word
开发者ID:wolfprogrammer,项目名称:password-generator,代码行数:10,代码来源:passgen.py

示例15: check

 def check(self, val, client_id=None):
     if client_id is None:
         final_set = self.get(random.choice(list(self.client_list)))
     else:
         final_set = self.get(client_id)
     final_set = eval(final_set)
     if val in final_set:
         return True
     else:
         return False
开发者ID:julianpistorius,项目名称:crdt-py,代码行数:10,代码来源:TwoPSet.py


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