python 난수 생 성

975 단어 applecpythonimport
import random

#    :
random.randint(0,99)
#21

#    0 100    :
random.randrange(0, 101, 2)
#42

#     :
random.random() 
#0.85415370477785668
random.uniform(1, 10)
#5.4221167969800881

#    :
random.choice('abcdefg&#%^*f')
#'d'


#              :
random.sample('abcdefghij',3) 
#['a', 'd', 'b']


#                    :
''.join(random.sample(['a','b','c','d','e','f','g','h','i','j'], 3)).replace(" ","")
#'fih'


#       :
random.choice ( ['apple', 'pear', 'peach', 'orange', 'lemon'] )
#'lemon'


#  :

items = [1, 2, 3, 4, 5, 6]
random.shuffle(items)
items
#[3, 2, 5, 6, 4, 1]

refer:
참고 자료:http://docs.python.org/lib/module-random.html http://blog.chinaunix.net/space.php?uid=20587169&do=blog&cuid=373575

좋은 웹페이지 즐겨찾기