fixed the order randnum generates parameters and a few array indexing issues