You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
648 B
30 lines
648 B
9 years ago
|
try:
|
||
2 years ago
|
import random
|
||
9 years ago
|
except ImportError:
|
||
2 years ago
|
print("SKIP")
|
||
|
raise SystemExit
|
||
9 years ago
|
|
||
|
# 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)
|
||
8 years ago
|
|
||
3 years ago
|
# check that zero bits works
|
||
|
print(random.getrandbits(0))
|
||
|
|
||
|
# check that it throws an error for negative bits
|
||
8 years ago
|
try:
|
||
3 years ago
|
random.getrandbits(-1)
|
||
8 years ago
|
except ValueError:
|
||
5 years ago
|
print("ValueError")
|