May 7, 2017

[HDGEM] Generating random number in Python

import random

# We create a set of digits: {0, 1, .... 9}
digits = set(range(10))
# We generate a random integer, 1 <= first <= 9
first = random.randint(1, 9)
# take a sample of
# 3 distinct elements from the set
r3 = random.sample(digits, 3)

--
Posted By Blogger to HDGEM at 5/07/2017 03:52:00 AM