1# generate random integer values
2from random import randint
3
4value = randint(0, 10)
5print(value)
6
1# imports random
2import random
3# randint generates a random integar between the first parameter and the second
4print(random.randint(1, 100))
1# generate random integer values
2from random import seed
3from random import randint
4# seed random number generator
5seed(1)
6# generate some integers
7for _ in range(10):
8 value = randint(0, 10)
9 print(value)
10
1import numpy
2x = numpy.random.randint(100)
3# 63
4
5x = numpy.random.randint(100, size=5)
6# [60 50 55 30 88]
7
8x = numpy.random.rand()
9# 0.37588774033323125
10
11x = numpy.random.rand(5)
12# [0.41746837 0.67201216 0.55337301 0.51383033 0.21457139]
13
14x = numpy.random.rand(2,3)
15# [[0.19597024 0.65582147 0.3804617 ]
16# [0.5601902 0.5976546 0.58099592]]
17
18x = numpy.random.choice([1,5,2,3,4])
19# 3
20
21x = numpy.random.choice([1,5,2,3,4], size=(2,3))
22# [[2 4 1]
23# [3 3 3]]
24
25import random
26x = random.getrandbits(1)
27# True