random half algorithm added