def test_egsfor_ranlux_randomset(self): """Test RANLUX random number generator""" # Based on ranlux_test.mortran in EGSnrc # Assumes default egsfortran random macros egsfortran.init_ranlux(1, 1) egsfortran.ranlux(rng_array) egsfortran.randomm.rng_seed = 1 first10_sum = sum(randomset() for x in range(10)) assert 6.041212022304535 == first10_sum first10k_sum = first10_sum + sum(randomset() for x in range(9990)) assert 5037.366532325745 == first10k_sum
def randomset(): global rng_seed if rng_seed > 24: ranlux(rng_array) randomm.rng_seed = 1 random_num = rng_array[rng_seed - 1] randomm.rng_seed += 1 # logger.info(f"** Random: {random_num} **") return random_num
def test_egsfor_ranlux_iter(self): """Test RANLUX random number generator as an iterator""" # Based on ranlux_test.mortran in EGSnrc # Assumes default egsfortran random macros egsfortran.init_ranlux(1, 1) egsfortran.ranlux(rng_array) rnd_iter = random_iter() first10_sum = sum(next(rnd_iter) for i in range(10)) assert 6.041212022304535 == first10_sum first10k_sum = first10_sum + sum(next(rnd_iter) for x in range(9990)) assert 5037.366532325745 == first10k_sum first_million_sum = first10k_sum + sum( next(rnd_iter) for x in range(990_000)) assert 500181.8234628493 == first_million_sum
def random_iter(): while True: yield from rng_array ranlux(rng_array)
def setup(self): tutor4.init() egsfortran.init_ranlux(1, 0) egsfortran.ranlux(egsfortran.randomm.rng_array) egsfortran.randomm.rng_seed = 1