Python random number

In Python programming language, there are different functions that can be used to generate random numbers.
-randint(a,b) is to generate random integer numbers in the range of a and b.
-random() is to generate random floating-point numbers in the range of 0.0 and 1.0.
-uniform(a,b) is to generate random real numbers in the range of a and b (excluding b). The three random number functions are in random module. The three examples below demonstrate the use of each functions respectively.

from random import randint
for i in range(1,10):
print randint(1,100)
............................................
from random import random
for i in range(1,10):
print random()
...........................................
from random import uniform
for i in range(1,10):
print uniform(1.2,10.5)

Posted by: Dara | post date: 02-07-2013 | Subject: Python Programming Language




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.