Skip to content

Commit

Permalink
Merge pull request lcompilers#2543 from syheliel/random_fix
Browse files Browse the repository at this point in the history
refine testcase for random
  • Loading branch information
certik committed Feb 18, 2024
2 parents 960fdda + 0825a70 commit 5c7e247
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions integration_tests/test_random_02.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
from lpython import f64
from lpython import i32, f64
import random

def test_seed():
random.seed()
t1: f64 = random.random()
t2: f64 = random.random()
print(t1, t2)
assert abs(t1 - t2) > 1e-3
"""test the distribution of random"""
num_samples:i32 = 100000
bins: list[i32] = [0]*10
_ : i32
for _ in range(num_samples):
val: f64 = random.random()
assert val >= 0.0 and val < 1.0 # value out of range
bins[i32(val * 10.0)] += 1 # increment the appropriate bin

# Check that no bin has significantly more or fewer values than expected
expected_bin_count:i32 = i32(num_samples / 10)
count : i32
for count in bins:
blas: f64 = f64(abs(count - expected_bin_count))
assert blas < f64(expected_bin_count) * 0.05 # allow 5% deviation

test_seed()

0 comments on commit 5c7e247

Please sign in to comment.