Description of the function of the random module in Python

Source: Internet
Author: User

The random function describes the following methods of the random module:
  1. betavariate

    get a random floating-point number before range (0,1)

      method: Random.betavariate (Alpha,beta) return value: Float For example: print (Random.betavariate (3,4)) > >> 0.4179835782470355# This method requires two parameters that are greater than 0 to execute, that is, two parameter types need to be numeric types. 
  2. choice

    Random get elements of a non-empty sequence

      method: Random.choice (SEQ) return Value: Object For example: print (Random.choice (' abc ')) >>> a# The parameters passed in need to be a sequence or an iterative object  
  3. Expovariate

    Random acquisition of 1/n averages to infinity floating-point numbers

    方法:random.expovariate(num)返回值:float例如:print(random.expovariate(100)) >>> 0.002053324332834578#由于传入的参数是作为1的除数,因此不能是零,可以是正负数。
  4. Gammavariate
  5. Gauss
  6. GetState
  7. Lognormvariate
  8. Normalvariate
  9. Paretovariate
  10. Random.randint

    Randomly gets an integer from the specified integer range

    方法:random.randint(start,stop)返回值:int例如:print(random.randint(1,2)) >>> 2#上述取值包含结束的整数
  11. randrange

    randomly gets an integer from the specified integer range

      method: Random.randrange (Start,stop=none,step=1) return value: Int for example: print (Random.randrange ( -2,2 ) >>> # This method, when the starting value is positive, you can not specify the end value, the starting value is negative, you must specify the end value, or the program error, the method can also specify the step size. 
  12. Sample

    Gets the specified number of random objects from the specified range and returns them as a list

    方法:random.sample(seq,num)返回值:object例如:print(random.sample(‘abc‘,2)) >>> [‘b‘,‘a‘]#上述的num参数必须小于等于seq序列的长度,否则程序报错
  13. Seed
  14. SetState
  15. Shuffle
  16. Triangular
  17. Uniform

    Gets a random floating-point number from the specified range

    方法:random.uniform(start,stop)返回值:float例如:print(random.uniform(-1,1.1)) >>> -0.5195993353320494#该方法传入的指定范围可以是浮点数,也可以是整数
  18. Vonmisesvariate
  19. Weibullvariate
  20. Random

    Get a random floating-point number in the 0-1 range

    方法:random.random()返回值:float例如:print(random.random()) >>> 0.9014274576114836#该方法不用穿参数。

Description of the function of the random module in Python

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.