make function randomFeatures() shorter
add test cases, and some bug fixes, refactors