File tree Expand file tree Collapse file tree 1 file changed +16
-6
lines changed
Expand file tree Collapse file tree 1 file changed +16
-6
lines changed Original file line number Diff line number Diff line change 1- from lpython import f64
1+ from lpython import i32 , f64
22import random
33
44def test_seed ():
5- random .seed ()
6- t1 : f64 = random .random ()
7- t2 : f64 = random .random ()
8- print (t1 , t2 )
9- assert abs (t1 - t2 ) > 1e-3
5+ """test the distribution of random"""
6+ num_samples :i32 = 100000
7+ bins : list [i32 ] = [0 ]* 10
8+ _ : i32
9+ for _ in range (num_samples ):
10+ val : f64 = random .random ()
11+ assert val >= 0.0 and val < 1.0 # value out of range
12+ bins [i32 (val * 10.0 )] += 1 # increment the appropriate bin
13+
14+ # Check that no bin has significantly more or fewer values than expected
15+ expected_bin_count :i32 = i32 (num_samples / 10 )
16+ count : i32
17+ for count in bins :
18+ blas : f64 = f64 (abs (count - expected_bin_count ))
19+ assert blas < f64 (expected_bin_count ) * 0.05 # allow 5% deviation
1020
1121test_seed ()
You can’t perform that action at this time.
0 commit comments