mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
Update 70_random.py
This commit is contained in:
parent
7095db428c
commit
e5097f734f
@ -42,3 +42,17 @@ try:
|
||||
exit(1)
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
seq = [1, 2, 3, 4]
|
||||
weights = [0.1, 0.2, 0.2, 0.5]
|
||||
k = 1000
|
||||
res = r.choices(seq, weights, k=k)
|
||||
assert len(res) == k and isinstance(res, list)
|
||||
|
||||
max_error = 0.03
|
||||
for i in range(len(seq)):
|
||||
actual_w = res.count(seq[i]) / k
|
||||
assert abs(actual_w - weights[i]) < max_error
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user