pub-3785248829033902 | Python: Random #1 | - Big data with Python

| Python: Random #1 |

This module implements random number generators for various distributions.

For integers, uniform selection from a range. For sequences, uniform selection of a random element, a function to generate a random permutation of a list in-place, and a function for random sampling without replacement.

The best way to learn new things is to take a practical approach of the things you want to learn. Here is a fragment of code that demonstrates the use of the random number statement in Python:

Æ’ python command

import random
print(random.randrange(1, 5))
print(random.randint(6, 22))
print(random.uniform(2, 3))
print(random.choice( ['tesla', 'bmw', 'mercedes'] ))
curiousity = [5, 1145, False, 44, "TESLA", 333, "BMW"]
print(random.choice(curiousity))

output

3
8
2.9602560055128455
tesla
BMW


Previous
Next Post »