# Posted By

denakitan on 10/06/11

# Statistics

Viewed 220 times
Favorited by 0 user(s)

# Python - Random Numbers - Examples

/ Published in: Python Save to your folder(s) Example of some random number generation mechanisms built-in Python. More details in the following link: http://docs.python.org/library/random.html

Copy this code and paste it in your HTML
`import random from decimal import Decimal if __name__ == '__main__':     # the most basic random function. Generates a floating-point number between 0.0 and 1.0    print random.random()      # prints a random integer between the two numbers given    # perfect to bet in the 'MEGA-SENA' lottery    print random.randint(1, 60)     # random.uniform() returns a floating-points number between the two numbers given    # prints this number converted to decimal after rounding it to four places    FOURPLACES = Decimal(10) ** -4 # same as Decimal('0.0001')    print Decimal(str(random.uniform(1.6, 2.0))).quantize(FOURPLACES)`

## Comments Subscribe to comments

You need to login to post a comment.