Python Program to Generate a Random Number

Pubblicato il: 22 ottobre 2021
sul canale di: CodeLSC
46
1

Python is a simple, general purpose, high level, and object-oriented programming language.

Python is an interpreted scripting language also. Guido Van Rossum is known as the founder of Python programming.
==========================================================
Python Program to Generate a Random Number :
1.Generating a Random Number :
The random module provides a random() method which generates a float number between 0 and 1.

#code 1:
import random
n = random.random()
print(n)

2.Generating a Number within a Given Range
Python random module provides the randint() method that generates an integer number within a specific range. We can pass the two numbers as arguments that defines the range.

code 2:
import random
n = random.randint(0,50)
print(n)

3.Using random.sample()
The random module also provides the sample() method, which directly generates a list of random numbers. Below is the example of generating random numbers using the sample() method.

code 3:
import random
#Generate 5 random numbers between 10 and 30
random_list = random.sample(range(10, 40), 6)
print(random_list)
============================================================
#pythonprogram
#learnpython
#quadratic_equation
#Generate_a_Random_Number
#python_equation
#RandomNumber
========================================


In questa pagina del sito puoi guardare il video online Python Program to Generate a Random Number della durata di ore minuti seconda in buona qualità , che l'utente ha caricato CodeLSC 22 ottobre 2021, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 46 volte e gli è piaciuto 1 spettatori. Buona visione!