summaryrefslogtreecommitdiffstatshomepage
path: root/tests/extmod/urandom_basic.py
blob: 7e4d8bf34c5e5f4423c46f7a6606545e9c7a0b85 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
try:
    import urandom as random
except ImportError:
    import random

# check getrandbits returns a value within the bit range
for b in (1, 2, 3, 4, 16, 32):
    for i in range(50):
        assert random.getrandbits(b) < (1 << b)

# check that seed(0) gives a non-zero value
random.seed(0)
print(random.getrandbits(16) != 0)

# check that PRNG is repeatable
random.seed(1)
r = random.getrandbits(16)
random.seed(1)
print(random.getrandbits(16) == r)