finish random generation function