Random function

Most Widely used Random functions in Python

Most Widely used Random functions in Python

Nitesh Avatar

Share this:

Random function
  • Random module is used to generate pseudo-random number.
  • Random module consist on different built in function but most widely used random functions is menion below.

random()

  • It Generate pseudo-random float numbers.
  • The statement random.random() method return the floating point number that is in the range of [0, 1) but not including 1.0.
  • Takes no positional argument.

Syntax-random.random()

Random function
random.random()

randrang()

  • It chooses an integer and define the range in-between.
  • randrange can take more than one argument randrange(start, stop, step)
  • randrange(a,b) will return a<=value< b
  • Generate the random number within specified limit.

Syntax –random.randrange(start, stop [, step])

random.randrange()
random.randrange()

randint()

  • Generate the random number within specified limit.
  • It  will return a<=value<= b.
  • List object can not be used.
  • Takes 2 positional arguments.
  • Used when we know the start and end values.

Syntax-random.randint(start, stop)

random.randint()
random.randint()

uniform()

  • It chooses a floating point number that is defined in the range.
  • It takes two parameters.
  • This function generates a random float number which is greater than or equal to the start number and less than or equal to the stop number.

Syntax-random.uniform(start, stop)

random.uniform()
random.uniform()

choice()

This method introduced in python version 3.6 and it can repeat the elements.

  • It is used when you want to select an item at random in a given range or a list or something that is iterable. 

Syntax-random.choice(iterable element)

random.choice()
random.choice()

seed()

  • This function is used to generate the fixed value each time.
  • This is very helpful when we are working in testing envirnoment before production.

Syntax- random.seed(number)

random.seed(number)
random.seed()

This is a short description about random function and its implementation I think you enjoyed this post .if you have any query related to this post then let us known in the comment section.

Happy Learning!! 

 

 

Category:

Leave a Reply

Your email address will not be published. Required fields are marked *

Nitesh Avatar

Hi, I’m Steven, a Florida native, who left my career in corporate wealth management six years ago to embark on a summer of soul searching that would change the course of my life forever.

RECENT POST


RECENT COMMENT