fixed function with random array generation